eslint-plugin-hyoban 0.4.0 → 0.5.0
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.
- package/dist/index.cjs +65 -10
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +65 -10
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -2,10 +2,68 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
2
2
|
|
|
3
3
|
var utils = require('@typescript-eslint/utils');
|
|
4
4
|
|
|
5
|
-
var version = "0.
|
|
5
|
+
var version = "0.5.0";
|
|
6
6
|
|
|
7
7
|
const createRule = utils.ESLintUtils.RuleCreator((name)=>`https://github.com/hyoban/eslint-plugin-hyoban/blob/main/src/${name}.ts`);
|
|
8
8
|
|
|
9
|
+
const rule$2 = createRule({
|
|
10
|
+
name: 'jsonc-inline-spacing',
|
|
11
|
+
meta: {
|
|
12
|
+
type: 'layout',
|
|
13
|
+
fixable: 'whitespace',
|
|
14
|
+
docs: {
|
|
15
|
+
description: 'Enforce consistent spacing around JSONC attributes'
|
|
16
|
+
},
|
|
17
|
+
messages: {
|
|
18
|
+
jsoncInlineSpacing: 'Expected correct spacing around JSONC attribute'
|
|
19
|
+
},
|
|
20
|
+
schema: []
|
|
21
|
+
},
|
|
22
|
+
defaultOptions: [],
|
|
23
|
+
create (context) {
|
|
24
|
+
return {
|
|
25
|
+
JSONObjectExpression (node) {
|
|
26
|
+
const { properties } = node;
|
|
27
|
+
const shouldIgnore = properties.length === 0 || node.loc.start.line !== node.loc.end.line || !properties.every((property)=>property.key.type !== 'JSONIdentifier' && property.key.raw && property.value.type === 'JSONLiteral' && property.value.raw && property?.loc.start.line === node?.loc.start.line);
|
|
28
|
+
if (shouldIgnore) return;
|
|
29
|
+
const source = context.sourceCode.getText(node);
|
|
30
|
+
// @ts-expect-error it's fine
|
|
31
|
+
const keys = properties.map((property)=>property.key.raw);
|
|
32
|
+
// @ts-expect-error it's fine
|
|
33
|
+
const values = properties.map((property)=>property.value.raw);
|
|
34
|
+
if (keys.length !== values.length) return;
|
|
35
|
+
const correctedSource = `{ ${keys.map((key, i)=>`${key}: ${values[i]}`).join(', ')} }`;
|
|
36
|
+
const needFix = source !== correctedSource;
|
|
37
|
+
if (!needFix) return;
|
|
38
|
+
context.report({
|
|
39
|
+
node: node,
|
|
40
|
+
messageId: 'jsoncInlineSpacing',
|
|
41
|
+
fix (fixer) {
|
|
42
|
+
return fixer.replaceTextRange(node.range, correctedSource);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
JSONArrayExpression (node) {
|
|
47
|
+
const { elements } = node;
|
|
48
|
+
const shouldIgnore = elements.length === 0 || node.loc.start.line !== node.loc.end.line || !elements.every((element)=>element?.type === 'JSONLiteral' && element?.loc.start.line === node?.loc.start.line);
|
|
49
|
+
if (shouldIgnore) return;
|
|
50
|
+
const values = elements.map((element)=>element.raw);
|
|
51
|
+
const source = context.sourceCode.getText(node);
|
|
52
|
+
const correctedSource = `[${values.join(', ')}]`;
|
|
53
|
+
const needFix = source !== correctedSource;
|
|
54
|
+
if (!needFix) return;
|
|
55
|
+
context.report({
|
|
56
|
+
node: node,
|
|
57
|
+
messageId: 'jsoncInlineSpacing',
|
|
58
|
+
fix (fixer) {
|
|
59
|
+
return fixer.replaceTextRange(node.range, correctedSource);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
9
67
|
const expressionTypesNoCheck = new Set([
|
|
10
68
|
utils.AST_NODE_TYPES.ConditionalExpression,
|
|
11
69
|
utils.AST_NODE_TYPES.JSXElement,
|
|
@@ -64,19 +122,14 @@ const rule$1 = createRule({
|
|
|
64
122
|
for (const [index, attribute] of attributes.entries()){
|
|
65
123
|
const nextAttribute = attributes[index + 1];
|
|
66
124
|
if (!nextAttribute) break;
|
|
67
|
-
const isSameLine = attribute.loc.end.line === nextAttribute.loc.start.line;
|
|
68
|
-
if (!isSameLine) continue;
|
|
69
125
|
const { range } = attribute;
|
|
70
126
|
const nextRange = nextAttribute.range;
|
|
71
127
|
const spaceBetween = nextRange[0] - range[1];
|
|
72
|
-
if (spaceBetween
|
|
128
|
+
if (spaceBetween === 0) {
|
|
73
129
|
context.report({
|
|
74
130
|
node: nextAttribute,
|
|
75
131
|
fix (fixer) {
|
|
76
|
-
return fixer.
|
|
77
|
-
range[1],
|
|
78
|
-
nextRange[0]
|
|
79
|
-
], ' ');
|
|
132
|
+
return fixer.insertTextBefore(nextAttribute, ' ');
|
|
80
133
|
},
|
|
81
134
|
messageId: 'jsxAttributeSpacing'
|
|
82
135
|
});
|
|
@@ -140,9 +193,11 @@ var index = {
|
|
|
140
193
|
name: 'hyoban',
|
|
141
194
|
version
|
|
142
195
|
},
|
|
196
|
+
/// keep-sorted
|
|
143
197
|
rules: {
|
|
144
|
-
'
|
|
145
|
-
'jsx-attribute-spacing': rule$1
|
|
198
|
+
'jsonc-inline-spacing': rule$2,
|
|
199
|
+
'jsx-attribute-spacing': rule$1,
|
|
200
|
+
'prefer-early-return': rule
|
|
146
201
|
}
|
|
147
202
|
};
|
|
148
203
|
|
package/dist/index.d.cts
CHANGED
|
@@ -8,8 +8,9 @@ declare const _default: {
|
|
|
8
8
|
version: string;
|
|
9
9
|
};
|
|
10
10
|
rules: {
|
|
11
|
-
'
|
|
11
|
+
'jsonc-inline-spacing': _typescript_eslint_utils_ts_eslint.RuleModule<"jsoncInlineSpacing", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
12
12
|
'jsx-attribute-spacing': _typescript_eslint_utils_ts_eslint.RuleModule<MessageIds, [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
13
|
+
'prefer-early-return': _typescript_eslint_utils_ts_eslint.RuleModule<"preferEarlyReturn", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
13
14
|
};
|
|
14
15
|
};
|
|
15
16
|
|
package/dist/index.d.ts
CHANGED
|
@@ -8,8 +8,9 @@ declare const _default: {
|
|
|
8
8
|
version: string;
|
|
9
9
|
};
|
|
10
10
|
rules: {
|
|
11
|
-
'
|
|
11
|
+
'jsonc-inline-spacing': _typescript_eslint_utils_ts_eslint.RuleModule<"jsoncInlineSpacing", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
12
12
|
'jsx-attribute-spacing': _typescript_eslint_utils_ts_eslint.RuleModule<MessageIds, [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
13
|
+
'prefer-early-return': _typescript_eslint_utils_ts_eslint.RuleModule<"preferEarlyReturn", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
13
14
|
};
|
|
14
15
|
};
|
|
15
16
|
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,67 @@
|
|
|
1
1
|
import { ESLintUtils, AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
2
2
|
|
|
3
|
-
var version = "0.
|
|
3
|
+
var version = "0.5.0";
|
|
4
4
|
|
|
5
5
|
const createRule = ESLintUtils.RuleCreator((name)=>`https://github.com/hyoban/eslint-plugin-hyoban/blob/main/src/${name}.ts`);
|
|
6
6
|
|
|
7
|
+
const rule$2 = createRule({
|
|
8
|
+
name: 'jsonc-inline-spacing',
|
|
9
|
+
meta: {
|
|
10
|
+
type: 'layout',
|
|
11
|
+
fixable: 'whitespace',
|
|
12
|
+
docs: {
|
|
13
|
+
description: 'Enforce consistent spacing around JSONC attributes'
|
|
14
|
+
},
|
|
15
|
+
messages: {
|
|
16
|
+
jsoncInlineSpacing: 'Expected correct spacing around JSONC attribute'
|
|
17
|
+
},
|
|
18
|
+
schema: []
|
|
19
|
+
},
|
|
20
|
+
defaultOptions: [],
|
|
21
|
+
create (context) {
|
|
22
|
+
return {
|
|
23
|
+
JSONObjectExpression (node) {
|
|
24
|
+
const { properties } = node;
|
|
25
|
+
const shouldIgnore = properties.length === 0 || node.loc.start.line !== node.loc.end.line || !properties.every((property)=>property.key.type !== 'JSONIdentifier' && property.key.raw && property.value.type === 'JSONLiteral' && property.value.raw && property?.loc.start.line === node?.loc.start.line);
|
|
26
|
+
if (shouldIgnore) return;
|
|
27
|
+
const source = context.sourceCode.getText(node);
|
|
28
|
+
// @ts-expect-error it's fine
|
|
29
|
+
const keys = properties.map((property)=>property.key.raw);
|
|
30
|
+
// @ts-expect-error it's fine
|
|
31
|
+
const values = properties.map((property)=>property.value.raw);
|
|
32
|
+
if (keys.length !== values.length) return;
|
|
33
|
+
const correctedSource = `{ ${keys.map((key, i)=>`${key}: ${values[i]}`).join(', ')} }`;
|
|
34
|
+
const needFix = source !== correctedSource;
|
|
35
|
+
if (!needFix) return;
|
|
36
|
+
context.report({
|
|
37
|
+
node: node,
|
|
38
|
+
messageId: 'jsoncInlineSpacing',
|
|
39
|
+
fix (fixer) {
|
|
40
|
+
return fixer.replaceTextRange(node.range, correctedSource);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
JSONArrayExpression (node) {
|
|
45
|
+
const { elements } = node;
|
|
46
|
+
const shouldIgnore = elements.length === 0 || node.loc.start.line !== node.loc.end.line || !elements.every((element)=>element?.type === 'JSONLiteral' && element?.loc.start.line === node?.loc.start.line);
|
|
47
|
+
if (shouldIgnore) return;
|
|
48
|
+
const values = elements.map((element)=>element.raw);
|
|
49
|
+
const source = context.sourceCode.getText(node);
|
|
50
|
+
const correctedSource = `[${values.join(', ')}]`;
|
|
51
|
+
const needFix = source !== correctedSource;
|
|
52
|
+
if (!needFix) return;
|
|
53
|
+
context.report({
|
|
54
|
+
node: node,
|
|
55
|
+
messageId: 'jsoncInlineSpacing',
|
|
56
|
+
fix (fixer) {
|
|
57
|
+
return fixer.replaceTextRange(node.range, correctedSource);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
7
65
|
const expressionTypesNoCheck = new Set([
|
|
8
66
|
AST_NODE_TYPES.ConditionalExpression,
|
|
9
67
|
AST_NODE_TYPES.JSXElement,
|
|
@@ -62,19 +120,14 @@ const rule$1 = createRule({
|
|
|
62
120
|
for (const [index, attribute] of attributes.entries()){
|
|
63
121
|
const nextAttribute = attributes[index + 1];
|
|
64
122
|
if (!nextAttribute) break;
|
|
65
|
-
const isSameLine = attribute.loc.end.line === nextAttribute.loc.start.line;
|
|
66
|
-
if (!isSameLine) continue;
|
|
67
123
|
const { range } = attribute;
|
|
68
124
|
const nextRange = nextAttribute.range;
|
|
69
125
|
const spaceBetween = nextRange[0] - range[1];
|
|
70
|
-
if (spaceBetween
|
|
126
|
+
if (spaceBetween === 0) {
|
|
71
127
|
context.report({
|
|
72
128
|
node: nextAttribute,
|
|
73
129
|
fix (fixer) {
|
|
74
|
-
return fixer.
|
|
75
|
-
range[1],
|
|
76
|
-
nextRange[0]
|
|
77
|
-
], ' ');
|
|
130
|
+
return fixer.insertTextBefore(nextAttribute, ' ');
|
|
78
131
|
},
|
|
79
132
|
messageId: 'jsxAttributeSpacing'
|
|
80
133
|
});
|
|
@@ -138,9 +191,11 @@ var index = {
|
|
|
138
191
|
name: 'hyoban',
|
|
139
192
|
version
|
|
140
193
|
},
|
|
194
|
+
/// keep-sorted
|
|
141
195
|
rules: {
|
|
142
|
-
'
|
|
143
|
-
'jsx-attribute-spacing': rule$1
|
|
196
|
+
'jsonc-inline-spacing': rule$2,
|
|
197
|
+
'jsx-attribute-spacing': rule$1,
|
|
198
|
+
'prefer-early-return': rule
|
|
144
199
|
}
|
|
145
200
|
};
|
|
146
201
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-hyoban",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"description": "Hyoban extended ESLint rules.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "hyoban",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"eslint": "^9.2.0",
|
|
56
56
|
"eslint-config-hyoban": "^2.2.5",
|
|
57
57
|
"eslint-vitest-rule-tester": "^0.2.1",
|
|
58
|
+
"jsonc-eslint-parser": "^2.4.0",
|
|
58
59
|
"typescript": "^5.4.5",
|
|
59
60
|
"vitest": "^1.6.0"
|
|
60
61
|
},
|