lint-rules-alvin 1.1.0 → 1.1.2

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.
@@ -5,6 +5,7 @@ import { jsxNoSingleObjectCurlyNewlineRule } from '../custom_rules/jsx-no-single
5
5
  import { maxChainPerLineRule } from '../custom_rules/max-chain-per-line.js';
6
6
  import { multilineParenNewlineRule } from '../custom_rules/multiline-paren-newline.js';
7
7
  import { multilineArrayAccessorNewlineRule } from '../custom_rules/multiline-array-accessor-newline.js';
8
+ import { destructureNewlineRule } from '../custom_rules/destructure-newline.js';
8
9
 
9
10
  /**
10
11
  * Provides a config that creates a plugin and configures custom rules.
@@ -21,7 +22,8 @@ export const custom = {
21
22
  'jsx-no-single-object-curly-newline': jsxNoSingleObjectCurlyNewlineRule,
22
23
  'max-chain-per-line': maxChainPerLineRule,
23
24
  'multiline-paren-newline': multilineParenNewlineRule,
24
- 'multiline-array-accessor-newline': multilineArrayAccessorNewlineRule
25
+ 'multiline-array-accessor-newline': multilineArrayAccessorNewlineRule,
26
+ 'destructure-newline': destructureNewlineRule
25
27
  }
26
28
  }
27
29
  },
@@ -37,13 +39,18 @@ export const custom = {
37
39
  'error',
38
40
  {
39
41
  maxChain: 2,
40
- enforceSingleLine: true
42
+ enforceSingleLine: true,
43
+ checkSingleLink: true
41
44
  }
42
45
  ],
43
46
  'custom/multiline-paren-newline': [
44
47
  'error',
45
48
  { singleArgument: true }
46
49
  ],
47
- 'custom/multiline-array-accessor-newline': 'error'
50
+ 'custom/multiline-array-accessor-newline': 'error',
51
+ 'custom/destructure-newline': [
52
+ 'error',
53
+ { minItems: 2 }
54
+ ]
48
55
  }
49
56
  };
@@ -470,7 +470,7 @@ export const typescript = {
470
470
  '@typescript-eslint/strict-boolean-expressions': [
471
471
  'error',
472
472
  {
473
- allowAny: false,
473
+ allowAny: true,
474
474
  allowNullableBoolean: false,
475
475
  allowNullableEnum: false,
476
476
  allowNullableNumber: true,
@@ -0,0 +1,88 @@
1
+ /**
2
+ * @type {import('eslint').Rule.RuleModule}
3
+ */
4
+ export const destructureNewlineRule = {
5
+ meta: {
6
+ type: 'layout',
7
+ docs: {
8
+ description: 'Enforce newlines between properties in destructuring assignments',
9
+ category: 'Stylistic Issues',
10
+ recommended: false
11
+ },
12
+ fixable: 'whitespace',
13
+ schema: [
14
+ {
15
+ type: 'object',
16
+ properties: {
17
+ minItems: {
18
+ type: 'integer',
19
+ minimum: 2
20
+ }
21
+ },
22
+ additionalProperties: false
23
+ }
24
+ ],
25
+ messages: { error: 'There should be a newline between destructuring properties.' }
26
+ },
27
+
28
+ create(context) {
29
+
30
+ const sourceCode = context.sourceCode;
31
+ const { minItems = 2 } = context.options[0] || {};
32
+
33
+ return {
34
+ VariableDeclarator(node) {
35
+
36
+ if (node.id.type !== 'ObjectPattern') {
37
+
38
+ return;
39
+
40
+ }
41
+ const properties = node.id.properties;
42
+
43
+ if (properties.length < minItems) {
44
+
45
+ return;
46
+
47
+ }
48
+
49
+ for (let i = 0; i < properties.length - 1; i++) {
50
+
51
+ const currentProperty = properties[i];
52
+ const nextProperty = properties[i + 1];
53
+
54
+ const lastTokenOfCurrent = sourceCode.getLastToken(currentProperty);
55
+ const firstTokenOfNext = sourceCode.getFirstToken(nextProperty);
56
+
57
+ if (
58
+ lastTokenOfCurrent
59
+ .loc
60
+ .end
61
+ .line === firstTokenOfNext
62
+ .loc
63
+ .start
64
+ .line
65
+ ) {
66
+
67
+ context.report({
68
+ node: nextProperty,
69
+ messageId: 'error',
70
+ fix(fixer) {
71
+
72
+ return fixer.insertTextBefore(
73
+ nextProperty,
74
+ '\n'
75
+ );
76
+
77
+ }
78
+ });
79
+
80
+ }
81
+
82
+ }
83
+
84
+ }
85
+ };
86
+
87
+ }
88
+ };
@@ -86,13 +86,12 @@ export const jsxMultilinePropNewlineRule = {
86
86
  fix(fixer) {
87
87
 
88
88
  // Get indentation of the line with the opening tag.
89
- const line = sourceCode
90
- .getLines()[
91
- node
92
- .loc
93
- .start
94
- .line - 1
95
- ];
89
+ const line = sourceCode.getLines()[
90
+ node
91
+ .loc
92
+ .start
93
+ .line - 1
94
+ ];
96
95
  const baseIndentMatch = line.match(/^\s*/);
97
96
  const baseIndent = baseIndentMatch
98
97
  ? baseIndentMatch[0]
@@ -21,6 +21,10 @@ export const maxChainPerLineRule = {
21
21
  enforceSingleLine: {
22
22
  type: 'boolean',
23
23
  default: false
24
+ },
25
+ checkSingleLink: {
26
+ type: 'boolean',
27
+ default: false
24
28
  }
25
29
  },
26
30
  additionalProperties: false
@@ -34,9 +38,11 @@ export const maxChainPerLineRule = {
34
38
  create(context) {
35
39
 
36
40
  const {
37
- maxChain = 2, enforceSingleLine = false
41
+ maxChain = 2,
42
+ enforceSingleLine = false,
43
+ checkSingleLink = false
38
44
  } = context.options[0] || {};
39
- const sourceCode = context.getSourceCode();
45
+ const sourceCode = context.sourceCode;
40
46
  const processedChains = new Set();
41
47
 
42
48
  /**
@@ -123,7 +129,10 @@ export const maxChainPerLineRule = {
123
129
  const links = getChainLinks(outermostNode);
124
130
  const chainCount = links.length;
125
131
 
126
- if (chainCount <= 1) {
132
+ const minChain = checkSingleLink
133
+ ? 1
134
+ : 2;
135
+ if (chainCount < minChain) {
127
136
 
128
137
  return;
129
138
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lint-rules-alvin",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "My own personal linting ruleset for a bunch of different plugins. Includes a few custom rules. Used in a few of my repos.",
5
5
  "keywords": [
6
6
  "eslint"