Skip to content

Commit

Permalink
fix(eslint-plugin-experience): add new plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Jun 15, 2024
1 parent 5fc09de commit fd0da0a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions projects/eslint-plugin-experience/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ module.exports = {
'@angular-eslint/use-component-selector': 'off',
'@angular-eslint/use-component-view-encapsulation': 'off',
'@angular-eslint/use-injectable-provided-in': 'off',
'@taiga-ui/experience/no-postfix-class': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-base-to-string': 'off',
Expand Down
1 change: 1 addition & 0 deletions projects/eslint-plugin-experience/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
'injection-token-description': require('./rules/injection-token-description'),
'no-deep-imports': require('./rules/no-deep-imports'),
'no-implicit-public': require('./rules/no-implicit-public'),
'no-postfix-class': require('./rules/no-postfix-class'),
'no-private-esnext-fields': require('./rules/no-private-esnext-fields'),
'no-simple-for-of': require('./rules/no-simple-for-of'),
'strict-tui-doc-example': require('./rules/strict-tui-doc-example'),
Expand Down
33 changes: 33 additions & 0 deletions projects/eslint-plugin-experience/rules/no-postfix-class.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @type {import(`eslint`).Rule.RuleModule}
*/
module.exports = {
create(context) {
return {
ClassDeclaration: function reportUnwantedName(node) {
const name = node?.id?.name;

const hasPostfix = !!(
name?.endsWith('Component') || name?.endsWith('Directive')
);

if (!hasPostfix) {
return;
}

const isStandalone = !!(
node?.decorators?.find(
decorator => decorator?.expression?.callee?.name === 'Component',
)?.expression?.arguments?.[0]?.properties || []
).find(property => property?.key?.name === 'standalone');

if (isStandalone) {
context.report({
message: ` ${name} is standalone component, please rename it to ${name.replace(/Component|Directive/, '')}`,
node,
});
}
},
};
},
};

0 comments on commit fd0da0a

Please sign in to comment.