Skip to content

Commit

Permalink
feat(eslint-config-angular): support member ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Nov 17, 2021
1 parent ab0b6f6 commit a57a57d
Show file tree
Hide file tree
Showing 25 changed files with 8,571 additions and 3,478 deletions.
410 changes: 119 additions & 291 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"@types/eslint": "^7.2.0",
"@types/jest": "^26.0.0",
"@types/node": "^14.0.1",
"@typescript-eslint/eslint-plugin": "^5.3.0",
"@typescript-eslint/parser": "^5.3.0",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"babel-jest": "^26.0.1",
"concurrently": "5.0.1",
"conventional-changelog-conventionalcommits": "^4.2.3",
Expand Down
33 changes: 24 additions & 9 deletions packages/eslint-config-angular/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
module.exports = {
extends: [],

plugins: [],

rules: {
'import/no-webpack-loader-syntax': 'off',
'sort-class-members/sort-class-members': 'off',
'no-param-reassign': 'off',
'@typescript-eslint/no-useless-constructor': 'off',
'@typescript-eslint/no-extraneous-class': 'off', // incorrect working with constructor parameters
env: {
browser: true,
es6: true,
node: true,
},
parserOptions: {
createDefaultProgram: true,
project: 'tsconfig*.json',
sourceType: 'module',
errorOnUnknownASTType: true,
errorOnTypeScriptSyntacticAndSemanticIssues: true,
warnOnUnsupportedTypeScriptVersion: false,
},
overrides: [
{
files: ['*.ts'],
parser: '@typescript-eslint/parser',
plugins: ['sort-class-members', '@typescript-eslint'],
rules: {
...require('./rules/base'),
...require('./rules/import'),
...require('./rules/member-ordering'),
},
},
],
};
6 changes: 2 additions & 4 deletions packages/eslint-config-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
"type": "git",
"url": "https://github.com/TinkoffCreditSystems/linters.git"
},
"devDependencies": {
"@tinkoff/eslint-config": "^1.13.2"
},
"peerDependencies": {
"@typescript-eslint/eslint-plugin": "^5.3.0",
"@tinkoff/eslint-config": "^1.13.2",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"eslint": "^7.5.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-sort-class-members": "^1.7.0"
Expand Down
14 changes: 14 additions & 0 deletions packages/eslint-config-angular/rules/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @note: only rules from eslint base rules
*/
module.exports = {
'no-param-reassign': 'error',
'@typescript-eslint/no-extraneous-class': ['error'],

/**
* @note: note you must disable the base rule
* as it can report incorrect errors in @typescript-eslint
*/
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': ['error'],
};
6 changes: 6 additions & 0 deletions packages/eslint-config-angular/rules/import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @note: only rules for imports
*/
module.exports = {
'import/no-webpack-loader-syntax': 'off',
};
127 changes: 127 additions & 0 deletions packages/eslint-config-angular/rules/member-ordering.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/**
* @note: only rules which start with ^@typescript-eslint/
*/
module.exports = {
/**
* @note(splincode): use @typescript-eslint/member-ordering instead
*/
'sort-class-members/sort-class-members': 'off',
'@typescript-eslint/member-ordering': [
'error',
{
default: [
'signature',
/**
* static fields
* [sort: public -> protected -> private]
**/
'public-static-field',
'protected-static-field',
'private-static-field',

/**
* abstract fields
* [sort: public -> protected -> private]
**/
'public-abstract-field',
'protected-abstract-field',
'private-abstract-field',

/**
* instance fields
* [sort: private -> protected -> public]
* [sort: decorated -> non-decorated]
**/
'private-decorated-field',
'private-instance-field',
'protected-decorated-field',
'protected-instance-field',
'public-decorated-field',
'public-instance-field',

/**
* constructors
* [sort: public -> protected -> private]
**/
'public-constructor',
'protected-constructor',
'private-constructor',

/**
* @note(splincode):
* We have deliberately disabled this rule
* because it can break a lot of the codebase.
*
* static accessors
* [sort: public -> protected -> private]
**/
/*
'public-static-get',
'public-static-set',
'protected-static-get',
'protected-static-set',
'private-static-get',
'private-static-set',
*/

/**
* @note(splincode):
* We have deliberately disabled this rule
* because it can break a lot of the codebase.
*
* instance accessors
* [sort: public -> protected -> private]
* [sort: decorated -> non-decorated]
**/
/*
'public-decorated-get',
'public-instance-get',
'public-decorated-set',
'public-instance-set',
'protected-decorated-get',
'protected-instance-get',
'protected-decorated-set',
'protected-instance-set',
'private-decorated-get',
'private-instance-get',
'private-decorated-set',
'private-instance-set',
*/

/**
* static methods
* [sort: public -> protected -> private]
**/
'public-static-method',
'protected-static-method',
'private-static-method',

/**
* abstract
* [sort: public -> private -> protected]
**/
'public-abstract-get',
'public-abstract-set',
'protected-abstract-get',
'protected-abstract-set',
'private-abstract-get',
'private-abstract-set',
'public-abstract-method',
'protected-abstract-method',
'private-abstract-method',

/**
* methods
* [sort: public -> protected -> private]
* [sort: decorated -> non-decorated]
**/
'public-decorated-method',
'public-instance-method',
'protected-decorated-method',
'protected-instance-method',
'private-decorated-method',
'private-instance-method',
],
},
],
};
19 changes: 0 additions & 19 deletions packages/eslint-config-angular/test/index.test.js

This file was deleted.

Loading

0 comments on commit a57a57d

Please sign in to comment.