Skip to content

Commit

Permalink
feat(eslint-plugin-experience): add `@taiga-ui/experience/decorator-k…
Browse files Browse the repository at this point in the history
…ey-sort`
  • Loading branch information
splincode committed Nov 8, 2023
1 parent 8c2bfd9 commit 4ccf0d9
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 61 deletions.
64 changes: 64 additions & 0 deletions projects/eslint-plugin-experience/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,67 @@ module.exports = {
extends: ['plugin:@taiga-ui/experience/all'],
};
```

or just

`.eslintrc.js`

```js
module.exports = {
root: true,
plugins: ['@typescript-eslint', '@taiga-ui/experience'],
rules: {
'@taiga-ui/experience/injection-token-description': 'error',
'@taiga-ui/experience/prefer-inject-decorator': 'error',
'@taiga-ui/experience/prefer-self-destroy-service': 'error',
'@taiga-ui/experience/no-typeof': 'error',
'@taiga-ui/experience/no-private-esnext-fields': 'error',
'@taiga-ui/experience/no-deep-imports': [
'error',
{
currentProject: '(?<=projects/)([-\\w]+)',
ignoreImports: ['\\?raw', '@taiga-ui/testing/cypress', '@taiga-ui/testing/setup-jest'],
},
],
'@taiga-ui/experience/strict-tui-doc-example': 'error',
'@taiga-ui/experience/no-assert-without-ng-dev-mode': 'error',
'@taiga-ui/experience/decorator-key-sort': [
'error',
{
Component: [
'moduleId',
'standalone',
'signal',
'selector',
'template',
'templateUrl',
'styleUrls',
'styles',
'encapsulation',
'changeDetection',
'providers',
'viewProviders',
'animations',
'entryComponents',
'preserveWhitespaces',
'interpolation',
],
NgModule: [
'id',
'jit',
'imports',
'declarations',
'providers',
'exports',
'entryComponents',
'bootstrap',
'schemas',
],
Directive: ['selector', 'inputs', 'outputs', 'providers', 'exportAs', 'queries', 'host', 'jit'],
Injectable: ['providedIn'],
Pipe: ['name', 'pure'],
},
],
},
};
```
84 changes: 41 additions & 43 deletions projects/eslint-plugin-experience/configs/taiga.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,49 +26,47 @@ module.exports = {
'@taiga-ui/experience/decorator-key-sort': [
'error',
{
decorators: {
Component: [
'moduleId',
'standalone',
'signal',
'selector',
'template',
'templateUrl',
'styleUrls',
'styles',
'encapsulation',
'changeDetection',
'providers',
'viewProviders',
'animations',
'entryComponents',
'preserveWhitespaces',
'interpolation',
],
NgModule: [
'id',
'jit',
'imports',
'declarations',
'providers',
'exports',
'entryComponents',
'bootstrap',
'schemas',
],
Directive: [
'selector',
'inputs',
'outputs',
'providers',
'exportAs',
'queries',
'host',
'jit',
],
Injectable: ['providedIn'],
Pipe: ['name', 'pure'],
},
Component: [
'moduleId',
'standalone',
'signal',
'selector',
'template',
'templateUrl',
'styleUrls',
'styles',
'encapsulation',
'changeDetection',
'providers',
'viewProviders',
'animations',
'entryComponents',
'preserveWhitespaces',
'interpolation',
],
NgModule: [
'id',
'jit',
'imports',
'declarations',
'providers',
'exports',
'entryComponents',
'bootstrap',
'schemas',
],
Directive: [
'selector',
'inputs',
'outputs',
'providers',
'exportAs',
'queries',
'host',
'jit',
],
Injectable: ['providedIn'],
Pipe: ['name', 'pure'],
},
],
},
Expand Down
21 changes: 3 additions & 18 deletions projects/eslint-plugin-experience/rules/decorator-key-sort.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
const DEFAULT_OPTIONS = {
decorators: {},
};

/**
* @type {import(`eslint`).Rule.RuleModule}
*/
Expand All @@ -12,24 +8,13 @@ module.exports = {
schema: [
{
type: `object`,
properties: {
decorators: {
type: `object`,
description: `Decorators names and his keys order`,
properties: {
additionalProperties: true,
},
},
},
additionalProperties: false,
description: `Decorators names and his keys order`,
additionalProperties: true,
},
],
},
create(context) {
const {decorators: ORDER} = {
...DEFAULT_OPTIONS,
...(context.options[0] || {}),
};
const ORDER = context.options[0] || {};

return {
ClassDeclaration(node) {
Expand Down

0 comments on commit 4ccf0d9

Please sign in to comment.