diff --git a/packages/eslint-plugin-warp-drive/src/rules/require-singular-dasherized-resource-name.js b/packages/eslint-plugin-warp-drive/src/rules/require-singular-dasherized-resource-name.js index aa07104d2a..d9622128bb 100644 --- a/packages/eslint-plugin-warp-drive/src/rules/require-singular-dasherized-resource-name.js +++ b/packages/eslint-plugin-warp-drive/src/rules/require-singular-dasherized-resource-name.js @@ -1,4 +1,5 @@ -const { dasherize, singularize } = require('@ember-data/request-utils/string'); +const { dasherize, singularize } = require('inflection'); + /** @type {import('eslint').Rule.RuleModule} */ module.exports = { meta: { @@ -22,17 +23,22 @@ module.exports = { const args = decorator.arguments; // TODO: add support for passing normalize function to rule to test - const resourceName = args.at(0); // The first argument is the resource name - const normalizedResourceName = dasherize(singularize(resourceName.value)); + const resource = args.at(0); // The first argument is the resource name + const resourceName = resource.value; + const normalizedResourceName = dasherize(singularize(resourceName)); + + console.log({ resourceName, normalizedResourceName }); + console.log(resourceName === normalizedResourceName, 'true'); - if (resourceName.value === normalizedResourceName) { + if (resourceName !== normalizedResourceName) { context.report({ node, - message: `The @{{decorator}} decorator resource name should be singular and dasherized, but found '{{resourceName}}'.`, + message: `The @${node.callee.name} decorator resource name should be singular and dasherized (${normalizedResourceName}), but found '${resourceName}'.`, data: { decorator: decorator.callee.name, }, }); + return; } } }, diff --git a/packages/eslint-plugin-warp-drive/tests/no-invalid-relationships.js b/packages/eslint-plugin-warp-drive/tests/no-invalid-relationships.js index 96f8f09924..c213796bd8 100644 --- a/packages/eslint-plugin-warp-drive/tests/no-invalid-relationships.js +++ b/packages/eslint-plugin-warp-drive/tests/no-invalid-relationships.js @@ -7,8 +7,6 @@ const rule = require('../src/rules/no-invalid-relationships'); const RuleTester = require('eslint').RuleTester; -const parserOptions = { ecmaVersion: 2022, sourceType: 'module', requireConfigFile: false }; - const ruleTester = new RuleTester({ languageOptions: { parser: require('@babel/eslint-parser'), diff --git a/packages/eslint-plugin-warp-drive/tests/require-singular-dasherized-resource-name.js b/packages/eslint-plugin-warp-drive/tests/require-singular-dasherized-resource-name.js index 4dcd56aa83..a4ad9ead68 100644 --- a/packages/eslint-plugin-warp-drive/tests/require-singular-dasherized-resource-name.js +++ b/packages/eslint-plugin-warp-drive/tests/require-singular-dasherized-resource-name.js @@ -1,13 +1,23 @@ const rule = require('../src/rules/require-singular-dasherized-resource-name'); const RuleTester = require('eslint').RuleTester; -const eslintTester = new RuleTester({ - parserOptions: { ecmaVersion: 2015 }, +const ruleTester = new RuleTester({ + languageOptions: { + parser: require('@babel/eslint-parser'), + ecmaVersion: 'latest', + sourceType: 'module', + parserOptions: { + requireConfigFile: false, + babelOptions: { + babelrc: false, + configFile: false, + plugins: [[require.resolve('@babel/plugin-proposal-decorators'), { legacy: true }]], + }, + }, + }, }); -const messageId = 'warp-drive.require-singular-dasherized-resource-name'; - -eslintTester.run('resource-naming', rule, { +ruleTester.run('require-singular-dasherized-resource-name', rule, { valid: [ `import Model, { belongsTo } from '@ember-data/model'; @@ -30,14 +40,14 @@ eslintTester.run('resource-naming', rule, { invalid: [ { code: `import Model, { belongsTo } from '@ember-data/model'; - export default class extends Model { - @belongsTo('Post', { async: true, inverse: 'post-comments' }) post; + @belongsTo('Posts', { async: true, inverse: 'post-comments' }) post; }`, output: null, errors: [ { - message: 'The @{{decorator}} decorator resource name should be singular and dasherized, but found Post.', + message: + "The @belongsTo decorator resource name should be singular and dasherized (Post), but found 'Posts'.", type: 'CallExpression', }, ],