@croct/eslint-plugin 0.2.2 → 0.2.3-rc.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.
@@ -74,6 +74,12 @@ export declare const configs: {
74
74
  };
75
75
  })[];
76
76
  };
77
+ overrides: {
78
+ files: string[];
79
+ rules: {
80
+ 'sort-keys-fix/sort-keys-fix': string;
81
+ };
82
+ }[];
77
83
  };
78
84
  typescript: {
79
85
  extends: string[];
@@ -142,6 +148,10 @@ export declare const configs: {
142
148
  };
143
149
  })[];
144
150
  'no-undef': string;
151
+ '@typescript-eslint/no-namespace': string;
152
+ '@typescript-eslint/no-redeclare': (string | {
153
+ ignoreDeclarationMerge: boolean;
154
+ })[];
145
155
  'no-new-object'?: undefined;
146
156
  };
147
157
  plugins?: undefined;
@@ -178,6 +188,8 @@ export declare const configs: {
178
188
  '@typescript-eslint/object-curly-spacing'?: undefined;
179
189
  '@typescript-eslint/member-delimiter-style'?: undefined;
180
190
  'no-undef'?: undefined;
191
+ '@typescript-eslint/no-namespace'?: undefined;
192
+ '@typescript-eslint/no-redeclare'?: undefined;
181
193
  };
182
194
  env: {
183
195
  jest: boolean;
@@ -193,6 +205,10 @@ export declare const configs: {
193
205
  '@croct/complex-expression-spacing': string;
194
206
  '@croct/newline-per-chained-call': string;
195
207
  '@croct/min-chained-call-depth': string;
208
+ 'eslint-comments/disable-enable-pair': (string | {
209
+ allowWholeFile: boolean;
210
+ })[];
211
+ 'eslint-comments/require-description': string;
196
212
  'newline-per-chained-call': string;
197
213
  'no-plusplus': string;
198
214
  'array-bracket-newline': string[];
@@ -281,6 +297,7 @@ export declare const configs: {
281
297
  prev: string[];
282
298
  next: string;
283
299
  })[];
300
+ 'no-useless-escape': string;
284
301
  };
285
302
  overrides: {
286
303
  files: string[];
@@ -6,6 +6,10 @@ export declare const javascript: {
6
6
  '@croct/complex-expression-spacing': string;
7
7
  '@croct/newline-per-chained-call': string;
8
8
  '@croct/min-chained-call-depth': string;
9
+ 'eslint-comments/disable-enable-pair': (string | {
10
+ allowWholeFile: boolean;
11
+ })[];
12
+ 'eslint-comments/require-description': string;
9
13
  'newline-per-chained-call': string;
10
14
  'no-plusplus': string;
11
15
  'array-bracket-newline': string[];
@@ -94,6 +98,7 @@ export declare const javascript: {
94
98
  prev: string[];
95
99
  next: string;
96
100
  })[];
101
+ 'no-useless-escape': string;
97
102
  };
98
103
  overrides: {
99
104
  files: string[];
@@ -5,6 +5,7 @@ exports.javascript = {
5
5
  extends: [
6
6
  'plugin:jest/recommended',
7
7
  'airbnb-base',
8
+ 'plugin:eslint-comments/recommended',
8
9
  ],
9
10
  plugins: [
10
11
  'jest',
@@ -18,6 +19,13 @@ exports.javascript = {
18
19
  '@croct/complex-expression-spacing': 'error',
19
20
  '@croct/newline-per-chained-call': 'error',
20
21
  '@croct/min-chained-call-depth': 'error',
22
+ 'eslint-comments/disable-enable-pair': [
23
+ 'error',
24
+ {
25
+ allowWholeFile: true,
26
+ },
27
+ ],
28
+ 'eslint-comments/require-description': 'error',
21
29
  'newline-per-chained-call': 'off',
22
30
  'no-plusplus': 'off',
23
31
  'array-bracket-newline': [
@@ -205,6 +213,7 @@ exports.javascript = {
205
213
  ],
206
214
  },
207
215
  ],
216
+ 'no-useless-escape': 'error',
208
217
  },
209
218
  overrides: [
210
219
  {
@@ -60,4 +60,10 @@ export declare const react: {
60
60
  };
61
61
  })[];
62
62
  };
63
+ overrides: {
64
+ files: string[];
65
+ rules: {
66
+ 'sort-keys-fix/sort-keys-fix': string;
67
+ };
68
+ }[];
63
69
  };
package/configs/react.js CHANGED
@@ -17,6 +17,7 @@ exports.react = {
17
17
  'testing-library',
18
18
  'jest-dom',
19
19
  '@croct',
20
+ 'sort-keys-fix',
20
21
  ],
21
22
  rules: {
22
23
  '@croct/jsx-attribute-spacing': 'error',
@@ -120,4 +121,12 @@ exports.react = {
120
121
  },
121
122
  ],
122
123
  },
124
+ overrides: [
125
+ {
126
+ files: ['**/styles.ts'],
127
+ rules: {
128
+ 'sort-keys-fix/sort-keys-fix': 'error',
129
+ },
130
+ },
131
+ ],
123
132
  };
@@ -65,6 +65,10 @@ export declare const typescript: {
65
65
  };
66
66
  })[];
67
67
  'no-undef': string;
68
+ '@typescript-eslint/no-namespace': string;
69
+ '@typescript-eslint/no-redeclare': (string | {
70
+ ignoreDeclarationMerge: boolean;
71
+ })[];
68
72
  'no-new-object'?: undefined;
69
73
  };
70
74
  plugins?: undefined;
@@ -101,6 +105,8 @@ export declare const typescript: {
101
105
  '@typescript-eslint/object-curly-spacing'?: undefined;
102
106
  '@typescript-eslint/member-delimiter-style'?: undefined;
103
107
  'no-undef'?: undefined;
108
+ '@typescript-eslint/no-namespace'?: undefined;
109
+ '@typescript-eslint/no-redeclare'?: undefined;
104
110
  };
105
111
  env: {
106
112
  jest: boolean;
@@ -77,6 +77,10 @@ exports.typescript = {
77
77
  },
78
78
  }],
79
79
  'no-undef': 'off',
80
+ '@typescript-eslint/no-namespace': 'off',
81
+ '@typescript-eslint/no-redeclare': ['error', {
82
+ ignoreDeclarationMerge: true,
83
+ }],
80
84
  },
81
85
  },
82
86
  {
package/index.d.ts CHANGED
@@ -21,6 +21,7 @@ declare const configuration: {
21
21
  maxLineLength: number;
22
22
  }[], {
23
23
  CallExpression: (node: import("@typescript-eslint/types/dist/ast-spec").CallExpression) => void;
24
+ MemberExpression: (node: import("@typescript-eslint/types/dist/ast-spec").MemberExpression) => void;
24
25
  }>;
25
26
  };
26
27
  configs: {
@@ -99,6 +100,12 @@ declare const configuration: {
99
100
  };
100
101
  })[];
101
102
  };
103
+ overrides: {
104
+ files: string[];
105
+ rules: {
106
+ 'sort-keys-fix/sort-keys-fix': string;
107
+ };
108
+ }[];
102
109
  };
103
110
  typescript: {
104
111
  extends: string[];
@@ -167,6 +174,10 @@ declare const configuration: {
167
174
  };
168
175
  })[];
169
176
  'no-undef': string;
177
+ '@typescript-eslint/no-namespace': string;
178
+ '@typescript-eslint/no-redeclare': (string | {
179
+ ignoreDeclarationMerge: boolean;
180
+ })[];
170
181
  'no-new-object'?: undefined;
171
182
  };
172
183
  plugins?: undefined;
@@ -203,6 +214,8 @@ declare const configuration: {
203
214
  '@typescript-eslint/object-curly-spacing'?: undefined;
204
215
  '@typescript-eslint/member-delimiter-style'?: undefined;
205
216
  'no-undef'?: undefined;
217
+ '@typescript-eslint/no-namespace'?: undefined;
218
+ '@typescript-eslint/no-redeclare'?: undefined;
206
219
  };
207
220
  env: {
208
221
  jest: boolean;
@@ -218,6 +231,10 @@ declare const configuration: {
218
231
  '@croct/complex-expression-spacing': string;
219
232
  '@croct/newline-per-chained-call': string;
220
233
  '@croct/min-chained-call-depth': string;
234
+ 'eslint-comments/disable-enable-pair': (string | {
235
+ allowWholeFile: boolean;
236
+ })[];
237
+ 'eslint-comments/require-description': string;
221
238
  'newline-per-chained-call': string;
222
239
  'no-plusplus': string;
223
240
  'array-bracket-newline': string[];
@@ -306,6 +323,7 @@ declare const configuration: {
306
323
  prev: string[];
307
324
  next: string;
308
325
  })[];
326
+ 'no-useless-escape': string;
309
327
  };
310
328
  overrides: {
311
329
  files: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@croct/eslint-plugin",
3
- "version": "0.2.2",
3
+ "version": "0.2.3-rc.1",
4
4
  "description": "ESLint rules and presets applied to all Croct JavaScript projects.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -42,6 +42,7 @@
42
42
  "eslint-config-airbnb": "^19.0",
43
43
  "eslint-config-airbnb-base": "^15.0",
44
44
  "eslint-plugin-cypress": "^2.12",
45
+ "eslint-plugin-eslint-comments": "^3.2.0",
45
46
  "eslint-plugin-import": "^2.25",
46
47
  "eslint-plugin-import-newlines": "^1.1",
47
48
  "eslint-plugin-jest": "^26.1",
@@ -61,6 +62,7 @@
61
62
  "eslint": "^8.8",
62
63
  "eslint-plugin-eslint-plugin": "^4.1.0",
63
64
  "eslint-plugin-self": "^1.2.1",
65
+ "eslint-plugin-sort-keys-fix": "^1.1.2",
64
66
  "jest": "^27.5",
65
67
  "ts-jest": "^27.1",
66
68
  "typescript": "^4.5"
package/rules/index.d.ts CHANGED
@@ -20,5 +20,6 @@ export declare const rules: {
20
20
  maxLineLength: number;
21
21
  }[], {
22
22
  CallExpression: (node: import("@typescript-eslint/types/dist/ast-spec").CallExpression) => void;
23
+ MemberExpression: (node: import("@typescript-eslint/types/dist/ast-spec").MemberExpression) => void;
23
24
  }>;
24
25
  };
@@ -3,4 +3,5 @@ export declare const minChainedCallDepth: import("@typescript-eslint/utils/dist/
3
3
  maxLineLength: number;
4
4
  }[], {
5
5
  CallExpression: (node: TSESTree.CallExpression) => void;
6
+ MemberExpression: (node: TSESTree.MemberExpression) => void;
6
7
  }>;
@@ -43,28 +43,51 @@ exports.minChainedCallDepth = (0, createRule_1.createRule)({
43
43
  || currentNode.type === 'MemberExpression') {
44
44
  if (currentNode.type === 'MemberExpression') {
45
45
  currentNode = currentNode.object;
46
+ depth += 1;
46
47
  }
47
48
  else if (currentNode.type === 'CallExpression') {
48
49
  currentNode = currentNode.callee;
49
50
  }
50
- depth += 1;
51
51
  }
52
52
  return depth;
53
53
  }
54
54
  function check(node) {
55
- var _a, _b, _c;
56
- if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === 'MemberExpression'
57
- || ((_b = node.parent) === null || _b === void 0 ? void 0 : _b.type) === 'CallExpression'
58
- || node.callee.type !== 'MemberExpression'
59
- || node.callee.computed
60
- || node.callee.object.loc.end.line === node.callee.property.loc.start.line) {
55
+ 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.
58
+ //
59
+ // Example:
60
+ // ```ts
61
+ // foo
62
+ // .bar();
63
+ // ```
64
+ // The replacement of this input should be `foo.bar();`, which has 10 character.
65
+ // 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') {
61
67
  return;
62
68
  }
63
- if (getDepth(node) > 3) {
69
+ // If the node is a call expression we need to validate it's callee as a member
70
+ // expression.
71
+ // If the node itself is already a member expression, like the
72
+ // `property` in `this.property.function()`, we validate the node directly.
73
+ const callee = node.type === 'CallExpression' ? node.callee : node;
74
+ if (
75
+ // If the callee is not a member expression, we can skip.
76
+ // 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.
79
+ || callee.computed
80
+ // If the callee is already in the same line as it's object, we can skip.
81
+ || callee.object.loc.end.line === callee.property.loc.start.line) {
64
82
  return;
65
83
  }
66
- const { maxLineLength = 100 } = (_c = context.options[0]) !== null && _c !== void 0 ? _c : {};
67
- const { property } = node.callee;
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) {
87
+ return;
88
+ }
89
+ const { maxLineLength = 100 } = (_b = context.options[0]) !== null && _b !== void 0 ? _b : {};
90
+ const { property } = callee;
68
91
  const lastToken = sourceCode.getLastToken(node, {
69
92
  filter: token => token.loc.end.line === property.loc.start.line,
70
93
  });
@@ -73,14 +96,14 @@ exports.minChainedCallDepth = (0, createRule_1.createRule)({
73
96
  && token.type === 'Punctuator'
74
97
  && token.value === ';'),
75
98
  });
76
- const lineLength = node.callee.object.loc.end.column
99
+ const lineLength = callee.object.loc.end.column
77
100
  + lastToken.loc.end.column - property.loc.start.column
78
101
  + 1
79
102
  + (semicolon !== null ? 1 : 0);
80
103
  if (maxLineLength !== null && lineLength > maxLineLength) {
81
104
  return;
82
105
  }
83
- const punctuator = sourceCode.getTokenBefore(node.callee.property);
106
+ const punctuator = sourceCode.getTokenBefore(callee.property);
84
107
  const previousToken = sourceCode.getTokenBefore(punctuator, { includeComments: true });
85
108
  const nextToken = sourceCode.getTokenAfter(punctuator, { includeComments: true });
86
109
  if ((0, ast_utils_1.isCommentToken)(previousToken) || (0, ast_utils_1.isCommentToken)(nextToken)) {
@@ -89,8 +112,8 @@ exports.minChainedCallDepth = (0, createRule_1.createRule)({
89
112
  context.report({
90
113
  node: node,
91
114
  loc: {
92
- start: node.callee.object.loc.end,
93
- end: node.callee.property.loc.start,
115
+ start: callee.object.loc.end,
116
+ end: callee.property.loc.start,
94
117
  },
95
118
  messageId: 'unexpectedLineBreak',
96
119
  fix: fixer => fixer.replaceTextRange([previousToken.range[1], nextToken.range[0]], punctuator.value),
@@ -100,6 +123,9 @@ exports.minChainedCallDepth = (0, createRule_1.createRule)({
100
123
  CallExpression: (node) => {
101
124
  check(node);
102
125
  },
126
+ MemberExpression: (node) => {
127
+ check(node);
128
+ },
103
129
  };
104
130
  },
105
131
  });
@@ -42,8 +42,7 @@ exports.newlinePerChainedCall = (0, createRule_1.createRule)({
42
42
  const sourceCode = context.getSourceCode();
43
43
  function getPropertyText(node) {
44
44
  const prefix = '.';
45
- const lines = sourceCode.getText(node.property)
46
- .split(LINEBREAK_MATCHER);
45
+ const lines = sourceCode.getText(node.property).split(LINEBREAK_MATCHER);
47
46
  return prefix + lines[0];
48
47
  }
49
48
  function hasObjectAndPropertyOnSameLine(node) {
@@ -53,7 +52,7 @@ exports.newlinePerChainedCall = (0, createRule_1.createRule)({
53
52
  return token.value !== ')' || token.type !== 'Punctuator';
54
53
  }
55
54
  function validateCallExpressionIgnoreDepth(node) {
56
- var _a;
55
+ var _a, _b;
57
56
  let hasCallExpression = false;
58
57
  if (node.type === 'CallExpression') {
59
58
  hasCallExpression = true;
@@ -85,7 +84,8 @@ exports.newlinePerChainedCall = (0, createRule_1.createRule)({
85
84
  .filter(hasObjectAndPropertyOnSameLine);
86
85
  const rootNode = expressionsOnSameLine[expressionsOnSameLine.length - 1];
87
86
  if (rootNode.type === 'MemberExpression'
88
- && ((_a = rootNode.parent) === null || _a === void 0 ? void 0 : _a.type) === 'CallExpression'
87
+ && (((_a = rootNode.parent) === null || _a === void 0 ? void 0 : _a.type) === 'CallExpression'
88
+ || ((_b = rootNode.parent) === null || _b === void 0 ? void 0 : _b.type) === 'MemberExpression')
89
89
  && (rootNode.object.type === 'ThisExpression'
90
90
  || rootNode.object.type === 'Identifier')) {
91
91
  expressionsOnSameLine.pop();