@croct/eslint-plugin 0.4.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,6 +19,10 @@ export declare const configs: {
19
19
  '@croct/jsx-attribute-spacing': string;
20
20
  'react/jsx-wrap-multilines': string;
21
21
  'react/display-name': string;
22
+ 'react/jsx-sort-props': (string | {
23
+ noSortAlphabetically: boolean;
24
+ multiline: string;
25
+ })[];
22
26
  'jsx-quotes': string[];
23
27
  'react/jsx-newline': (string | {
24
28
  prevent: boolean;
@@ -75,12 +79,6 @@ export declare const configs: {
75
79
  };
76
80
  })[];
77
81
  };
78
- overrides: {
79
- files: string[];
80
- rules: {
81
- 'sort-keys-fix/sort-keys-fix': string;
82
- };
83
- }[];
84
82
  };
85
83
  typescript: {
86
84
  extends: string[];
@@ -151,9 +149,6 @@ export declare const configs: {
151
149
  })[];
152
150
  'no-undef': string;
153
151
  '@typescript-eslint/no-namespace': string;
154
- '@typescript-eslint/no-redeclare': (string | {
155
- ignoreDeclarationMerge: boolean;
156
- })[];
157
152
  'no-new-object'?: undefined;
158
153
  };
159
154
  plugins?: undefined;
@@ -192,7 +187,6 @@ export declare const configs: {
192
187
  '@typescript-eslint/member-delimiter-style'?: undefined;
193
188
  'no-undef'?: undefined;
194
189
  '@typescript-eslint/no-namespace'?: undefined;
195
- '@typescript-eslint/no-redeclare'?: undefined;
196
190
  };
197
191
  env: {
198
192
  jest: boolean;
@@ -73,7 +73,7 @@ exports.javascript = {
73
73
  'error',
74
74
  {
75
75
  items: 6,
76
- 'max-len': 100,
76
+ 'max-len': 120,
77
77
  },
78
78
  ],
79
79
  'no-smart-quotes/no-smart-quotes': 'error',
@@ -112,7 +112,7 @@ exports.javascript = {
112
112
  'max-len': [
113
113
  'error',
114
114
  {
115
- code: 100,
115
+ code: 120,
116
116
  ignoreStrings: false,
117
117
  ignoreComments: false,
118
118
  ignoreTemplateLiterals: false,
@@ -207,6 +207,8 @@ exports.javascript = {
207
207
  blankLine: 'always',
208
208
  prev: '*',
209
209
  next: [
210
+ 'break',
211
+ 'continue',
210
212
  'return',
211
213
  'if',
212
214
  'function',
@@ -5,6 +5,10 @@ export declare const react: {
5
5
  '@croct/jsx-attribute-spacing': string;
6
6
  'react/jsx-wrap-multilines': string;
7
7
  'react/display-name': string;
8
+ 'react/jsx-sort-props': (string | {
9
+ noSortAlphabetically: boolean;
10
+ multiline: string;
11
+ })[];
8
12
  'jsx-quotes': string[];
9
13
  'react/jsx-newline': (string | {
10
14
  prevent: boolean;
@@ -61,10 +65,4 @@ export declare const react: {
61
65
  };
62
66
  })[];
63
67
  };
64
- overrides: {
65
- files: string[];
66
- rules: {
67
- 'sort-keys-fix/sort-keys-fix': string;
68
- };
69
- }[];
70
68
  };
package/configs/react.js CHANGED
@@ -17,12 +17,18 @@ exports.react = {
17
17
  'testing-library',
18
18
  'jest-dom',
19
19
  '@croct',
20
- 'sort-keys-fix',
21
20
  ],
22
21
  rules: {
23
22
  '@croct/jsx-attribute-spacing': 'error',
24
23
  'react/jsx-wrap-multilines': 'error',
25
24
  'react/display-name': 'off',
25
+ 'react/jsx-sort-props': [
26
+ 'error',
27
+ {
28
+ noSortAlphabetically: true,
29
+ multiline: 'last',
30
+ },
31
+ ],
26
32
  'jsx-quotes': [
27
33
  'error',
28
34
  'prefer-double',
@@ -125,12 +131,4 @@ exports.react = {
125
131
  },
126
132
  ],
127
133
  },
128
- overrides: [
129
- {
130
- files: ['**/styles.ts'],
131
- rules: {
132
- 'sort-keys-fix/sort-keys-fix': 'error',
133
- },
134
- },
135
- ],
136
134
  };
@@ -67,9 +67,6 @@ export declare const typescript: {
67
67
  })[];
68
68
  'no-undef': string;
69
69
  '@typescript-eslint/no-namespace': string;
70
- '@typescript-eslint/no-redeclare': (string | {
71
- ignoreDeclarationMerge: boolean;
72
- })[];
73
70
  'no-new-object'?: undefined;
74
71
  };
75
72
  plugins?: undefined;
@@ -108,7 +105,6 @@ export declare const typescript: {
108
105
  '@typescript-eslint/member-delimiter-style'?: undefined;
109
106
  'no-undef'?: undefined;
110
107
  '@typescript-eslint/no-namespace'?: undefined;
111
- '@typescript-eslint/no-redeclare'?: undefined;
112
108
  };
113
109
  env: {
114
110
  jest: boolean;
@@ -79,9 +79,6 @@ exports.typescript = {
79
79
  }],
80
80
  'no-undef': 'off',
81
81
  '@typescript-eslint/no-namespace': 'off',
82
- '@typescript-eslint/no-redeclare': ['error', {
83
- ignoreDeclarationMerge: true,
84
- }],
85
82
  },
86
83
  },
87
84
  {
package/index.d.ts CHANGED
@@ -12,14 +12,18 @@ declare const configuration: {
12
12
  IfStatement: (node: import("@typescript-eslint/types/dist/generated/ast-spec").IfStatement) => void;
13
13
  }>;
14
14
  'newline-per-chained-call': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"expectedLineBreak", {
15
- ignoreChainWithDepth: number;
15
+ ignoreChainDeeperThan: number;
16
16
  }[], {
17
17
  CallExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").CallExpression) => void;
18
18
  MemberExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").MemberExpression) => void;
19
19
  }>;
20
- 'min-chained-call-depth': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"unexpectedLineBreak", {
20
+ 'min-chained-call-depth': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"unexpectedLineBreak", ({
21
21
  maxLineLength: number;
22
- }[], {
22
+ ignoreChainDeeperThan?: undefined;
23
+ } | {
24
+ ignoreChainDeeperThan: number;
25
+ maxLineLength?: undefined;
26
+ })[], {
23
27
  CallExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").CallExpression) => void;
24
28
  MemberExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").MemberExpression) => void;
25
29
  }>;
@@ -48,6 +52,10 @@ declare const configuration: {
48
52
  '@croct/jsx-attribute-spacing': string;
49
53
  'react/jsx-wrap-multilines': string;
50
54
  'react/display-name': string;
55
+ 'react/jsx-sort-props': (string | {
56
+ noSortAlphabetically: boolean;
57
+ multiline: string;
58
+ })[];
51
59
  'jsx-quotes': string[];
52
60
  'react/jsx-newline': (string | {
53
61
  prevent: boolean;
@@ -104,12 +112,6 @@ declare const configuration: {
104
112
  };
105
113
  })[];
106
114
  };
107
- overrides: {
108
- files: string[];
109
- rules: {
110
- 'sort-keys-fix/sort-keys-fix': string;
111
- };
112
- }[];
113
115
  };
114
116
  typescript: {
115
117
  extends: string[];
@@ -180,9 +182,6 @@ declare const configuration: {
180
182
  })[];
181
183
  'no-undef': string;
182
184
  '@typescript-eslint/no-namespace': string;
183
- '@typescript-eslint/no-redeclare': (string | {
184
- ignoreDeclarationMerge: boolean;
185
- })[];
186
185
  'no-new-object'?: undefined;
187
186
  };
188
187
  plugins?: undefined;
@@ -221,7 +220,6 @@ declare const configuration: {
221
220
  '@typescript-eslint/member-delimiter-style'?: undefined;
222
221
  'no-undef'?: undefined;
223
222
  '@typescript-eslint/no-namespace'?: undefined;
224
- '@typescript-eslint/no-redeclare'?: undefined;
225
223
  };
226
224
  env: {
227
225
  jest: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@croct/eslint-plugin",
3
- "version": "0.4.0",
3
+ "version": "0.6.1",
4
4
  "description": "ESLint rules and presets applied to all Croct JavaScript projects.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -63,9 +63,8 @@
63
63
  "eslint": "^8.8",
64
64
  "eslint-plugin-eslint-plugin": "^4.1.0",
65
65
  "eslint-plugin-self": "^1.2.1",
66
- "eslint-plugin-sort-keys-fix": "^1.1.2",
67
- "jest": "^27.5",
68
- "ts-jest": "^27.1",
66
+ "jest": "^28.0.0",
67
+ "ts-jest": "^28.0.0-next.3",
69
68
  "typescript": "^4.5"
70
69
  },
71
70
  "peerDependencies": {
package/rules/index.d.ts CHANGED
@@ -11,14 +11,18 @@ export declare const rules: {
11
11
  IfStatement: (node: import("@typescript-eslint/types/dist/generated/ast-spec").IfStatement) => void;
12
12
  }>;
13
13
  'newline-per-chained-call': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"expectedLineBreak", {
14
- ignoreChainWithDepth: number;
14
+ ignoreChainDeeperThan: number;
15
15
  }[], {
16
16
  CallExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").CallExpression) => void;
17
17
  MemberExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").MemberExpression) => void;
18
18
  }>;
19
- 'min-chained-call-depth': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"unexpectedLineBreak", {
19
+ 'min-chained-call-depth': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"unexpectedLineBreak", ({
20
20
  maxLineLength: number;
21
- }[], {
21
+ ignoreChainDeeperThan?: undefined;
22
+ } | {
23
+ ignoreChainDeeperThan: number;
24
+ maxLineLength?: undefined;
25
+ })[], {
22
26
  CallExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").CallExpression) => void;
23
27
  MemberExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").MemberExpression) => void;
24
28
  }>;
@@ -1,7 +1,11 @@
1
1
  import { TSESTree } from '@typescript-eslint/experimental-utils';
2
- export declare const minChainedCallDepth: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"unexpectedLineBreak", {
2
+ export declare const minChainedCallDepth: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"unexpectedLineBreak", ({
3
3
  maxLineLength: number;
4
- }[], {
4
+ ignoreChainDeeperThan?: undefined;
5
+ } | {
6
+ ignoreChainDeeperThan: number;
7
+ maxLineLength?: undefined;
8
+ })[], {
5
9
  CallExpression: (node: TSESTree.CallExpression) => void;
6
10
  MemberExpression: (node: TSESTree.MemberExpression) => void;
7
11
  }>;
@@ -1,6 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.minChainedCallDepth = void 0;
4
+ /*
5
+ eslint-disable @typescript-eslint/no-non-null-assertion
6
+ --
7
+ Disable the rule to reduce the number of branches
8
+ */
9
+ const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
4
10
  const ast_utils_1 = require("@typescript-eslint/utils/dist/ast-utils");
5
11
  const createRule_1 = require("../createRule");
6
12
  exports.minChainedCallDepth = (0, createRule_1.createRule)({
@@ -21,6 +27,12 @@ exports.minChainedCallDepth = (0, createRule_1.createRule)({
21
27
  minimum: 1,
22
28
  default: 100,
23
29
  },
30
+ ignoreChainDeeperThan: {
31
+ type: 'integer',
32
+ minimum: 1,
33
+ maximum: 10,
34
+ default: 2,
35
+ },
24
36
  },
25
37
  additionalProperties: false,
26
38
  },
@@ -33,19 +45,23 @@ exports.minChainedCallDepth = (0, createRule_1.createRule)({
33
45
  {
34
46
  maxLineLength: 100,
35
47
  },
48
+ {
49
+ ignoreChainDeeperThan: 3,
50
+ },
36
51
  ],
37
52
  create: context => {
38
53
  const sourceCode = context.getSourceCode();
54
+ let maxDepth = 0;
39
55
  function getDepth(node) {
40
56
  let depth = 0;
41
57
  let currentNode = node;
42
- while (currentNode.type === 'CallExpression'
43
- || currentNode.type === 'MemberExpression') {
44
- if (currentNode.type === 'MemberExpression') {
58
+ while (currentNode.type === experimental_utils_1.AST_NODE_TYPES.CallExpression
59
+ || currentNode.type === experimental_utils_1.AST_NODE_TYPES.MemberExpression) {
60
+ if (currentNode.type === experimental_utils_1.AST_NODE_TYPES.MemberExpression) {
45
61
  currentNode = currentNode.object;
46
62
  depth += 1;
47
63
  }
48
- else if (currentNode.type === 'CallExpression') {
64
+ else if (currentNode.type === experimental_utils_1.AST_NODE_TYPES.CallExpression) {
49
65
  currentNode = currentNode.callee;
50
66
  }
51
67
  }
@@ -53,8 +69,8 @@ exports.minChainedCallDepth = (0, createRule_1.createRule)({
53
69
  }
54
70
  function check(node) {
55
71
  var _a, _b;
56
- // If the node is a member expression inside a call expression skip, this is to ensure
57
- // that we consider the correct line length of the result.
72
+ // If the node is a member expression inside a call/new expression skip,
73
+ // this is to ensure that we consider the correct line length of the result.
58
74
  //
59
75
  // Example:
60
76
  // ```ts
@@ -63,37 +79,61 @@ exports.minChainedCallDepth = (0, createRule_1.createRule)({
63
79
  // ```
64
80
  // The replacement of this input should be `foo.bar();`, which has 10 character.
65
81
  // Without this check it would consider the length up to `r`, which is 7.
66
- if (node.type === 'MemberExpression' && ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === 'CallExpression') {
82
+ if (node.type === experimental_utils_1.AST_NODE_TYPES.MemberExpression
83
+ && ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === experimental_utils_1.AST_NODE_TYPES.CallExpression) {
67
84
  return;
68
85
  }
69
- // If the node is a call expression we need to validate it's callee as a member
86
+ // If the node is a call/new expression we need to validate it's callee as a member
70
87
  // expression.
71
88
  // If the node itself is already a member expression, like the
72
89
  // `property` in `this.property.function()`, we validate the node directly.
73
- const callee = node.type === 'CallExpression' ? node.callee : node;
90
+ const callee = node.type === experimental_utils_1.AST_NODE_TYPES.CallExpression
91
+ ? node.callee
92
+ : node;
74
93
  if (
75
- // If the callee is not a member expression, we can skip.
94
+ // If the callee is not a member expression, skip.
76
95
  // For example, root level calls like `foo();`.
77
- callee.type !== 'MemberExpression'
78
- // If the callee is a computed member expression, like `foo[bar]()`, we can skip.
96
+ callee.type !== experimental_utils_1.AST_NODE_TYPES.MemberExpression
97
+ // If the callee is a computed member expression, like `foo[bar]()`, skip.
79
98
  || callee.computed
80
- // If the callee is already in the same line as it's object, we can skip.
99
+ /* eslint-disable-next-line @typescript-eslint/ban-ts-comment --
100
+ * NewExpression is a possible callee object type
101
+ */
102
+ // @ts-ignore
103
+ || callee.object.type === experimental_utils_1.AST_NODE_TYPES.NewExpression
104
+ // If the callee is already in the same line as it's object, skip.
81
105
  || callee.object.loc.end.line === callee.property.loc.start.line) {
82
106
  return;
83
107
  }
84
- // We only inline the first level of chained calls.
85
- // If the current call is nested inside another call, we can skip.
86
- if (getDepth(callee) > 1) {
108
+ const currentDepth = getDepth(callee);
109
+ maxDepth = Math.max(maxDepth, currentDepth);
110
+ // Only affect the root level as the total depth is must be known.
111
+ // If the current call is nested inside another call, skip.
112
+ if (currentDepth > 1) {
113
+ return;
114
+ }
115
+ const { maxLineLength = 100, ignoreChainDeeperThan = 2 } = (_b = context.options[0]) !== null && _b !== void 0 ? _b : {};
116
+ // If the max depth is greater than ignore threshold, skip
117
+ //
118
+ // Example:
119
+ // ```ts
120
+ // Array(10)
121
+ // .fill(0)
122
+ // .map(x => x + 1)
123
+ // .slice(0, 5);
124
+ // ```
125
+ // In this case the depth is 3, and the default value of ignoreChainDeeperThan is 2.
126
+ // So the check can be skipped.
127
+ if (maxDepth > ignoreChainDeeperThan) {
87
128
  return;
88
129
  }
89
- const { maxLineLength = 100 } = (_b = context.options[0]) !== null && _b !== void 0 ? _b : {};
90
130
  const { property } = callee;
91
131
  const lastToken = sourceCode.getLastToken(node, {
92
132
  filter: token => token.loc.end.line === property.loc.start.line,
93
133
  });
94
134
  const semicolon = sourceCode.getLastToken(node.parent, {
95
135
  filter: token => (token.loc.start.line === property.loc.start.line
96
- && token.type === 'Punctuator'
136
+ && token.type === experimental_utils_1.AST_TOKEN_TYPES.Punctuator
97
137
  && token.value === ';'),
98
138
  });
99
139
  const lineLength = callee.object.loc.end.column
@@ -1,6 +1,6 @@
1
1
  import { TSESTree } from '@typescript-eslint/experimental-utils';
2
2
  export declare const newlinePerChainedCall: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"expectedLineBreak", {
3
- ignoreChainWithDepth: number;
3
+ ignoreChainDeeperThan: number;
4
4
  }[], {
5
5
  CallExpression: (node: TSESTree.CallExpression) => void;
6
6
  MemberExpression: (node: TSESTree.MemberExpression) => void;
@@ -16,7 +16,7 @@ exports.newlinePerChainedCall = (0, createRule_1.createRule)({
16
16
  {
17
17
  type: 'object',
18
18
  properties: {
19
- ignoreChainWithDepth: {
19
+ ignoreChainDeeperThan: {
20
20
  type: 'integer',
21
21
  minimum: 1,
22
22
  maximum: 10,
@@ -32,13 +32,13 @@ exports.newlinePerChainedCall = (0, createRule_1.createRule)({
32
32
  },
33
33
  defaultOptions: [
34
34
  {
35
- ignoreChainWithDepth: 2,
35
+ ignoreChainDeeperThan: 2,
36
36
  },
37
37
  ],
38
38
  create: context => {
39
39
  var _a, _b;
40
40
  const options = (_a = context.options[0]) !== null && _a !== void 0 ? _a : {};
41
- const ignoreChainWithDepth = (_b = options.ignoreChainWithDepth) !== null && _b !== void 0 ? _b : 2;
41
+ const ignoreChainWithDepth = (_b = options.ignoreChainDeeperThan) !== null && _b !== void 0 ? _b : 2;
42
42
  const sourceCode = context.getSourceCode();
43
43
  function getPropertyText(node) {
44
44
  const prefix = '.';