eslint-plugin-hyoban 0.4.1 → 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 +63 -3
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +63 -3
- 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,
|
|
@@ -135,9 +193,11 @@ var index = {
|
|
|
135
193
|
name: 'hyoban',
|
|
136
194
|
version
|
|
137
195
|
},
|
|
196
|
+
/// keep-sorted
|
|
138
197
|
rules: {
|
|
139
|
-
'
|
|
140
|
-
'jsx-attribute-spacing': rule$1
|
|
198
|
+
'jsonc-inline-spacing': rule$2,
|
|
199
|
+
'jsx-attribute-spacing': rule$1,
|
|
200
|
+
'prefer-early-return': rule
|
|
141
201
|
}
|
|
142
202
|
};
|
|
143
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,
|
|
@@ -133,9 +191,11 @@ var index = {
|
|
|
133
191
|
name: 'hyoban',
|
|
134
192
|
version
|
|
135
193
|
},
|
|
194
|
+
/// keep-sorted
|
|
136
195
|
rules: {
|
|
137
|
-
'
|
|
138
|
-
'jsx-attribute-spacing': rule$1
|
|
196
|
+
'jsonc-inline-spacing': rule$2,
|
|
197
|
+
'jsx-attribute-spacing': rule$1,
|
|
198
|
+
'prefer-early-return': rule
|
|
139
199
|
}
|
|
140
200
|
};
|
|
141
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
|
},
|