Skip to content

Commit

Permalink
feat: update require-singular-dasherized-resource-name rule to use @e…
Browse files Browse the repository at this point in the history
…mber-data/request-utils for normalization
  • Loading branch information
Baltazore committed Jan 10, 2025
1 parent b51ea74 commit 6a51f26
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions packages/eslint-plugin-warp-drive/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"requireindex": "^1.2.0"
},
"devDependencies": {
"@ember-data/request-utils": "workspace:5.4.0-alpha.122",
"@warp-drive/internal-config": "workspace:5.4.0-alpha.122",
"@babel/plugin-proposal-decorators": "7.25.7",
"@babel/core": "^7.24.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,24 @@ module.exports = {
},
},

create(context) {
const params = context.options[0] ?? { moduleName: 'inflection', methodNames: ['dasherize', 'singularize'] };
async create(context) {
const params = context.options[0] ?? {
moduleName: '@ember-data/request-utils/string',
methodNames: ['dasherize', 'singularize'],
};
const { moduleName, methodNames } = params;
let normalize;

try {
const module = require(moduleName);
const mod = await import('@ember-data/request-utils/string');
// const mod = await import(moduleName);
normalize = (value) => {
return methodNames.reduce((acc, methodName) => {
return module[methodName](acc);
return mod[methodName](acc);
}, value);
};
} catch (error) {
console.log(error);
context.report({
message: `Failed to load module '${moduleName}' or methods '${methodNames.join(', ')}'`,
});
Expand Down
11 changes: 0 additions & 11 deletions packages/eslint-plugin-warp-drive/tests/normalizer.js

This file was deleted.

9 changes: 9 additions & 0 deletions packages/eslint-plugin-warp-drive/tests/normalizer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Super naive normalizer for testing purposes
export function normalize(value) {
return value
.replace(/([A-Z])([A-Z][a-z])/g, '$1-$2')
.replace(/([a-z])([A-Z])/g, '$1-$2')
.replace(/_/g, '-')
.replace(/s$/, '')
.toLowerCase();
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ ruleTester.run('require-singular-dasherized-resource-name', rule, {
@hasMany('user-setting', { inverse: 'user' }) userSettings;
}
`,
options: [{ moduleName: require.resolve('./normalizer.js'), methodNames: ['normalize'] }],
options: [{ moduleName: require.resolve('./normalizer.mjs'), methodNames: ['normalize'] }],
errors: [
{
message:
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6a51f26

Please sign in to comment.