eslint-plugin-hyoban 0.2.8 → 0.3.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/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![bundle][bundle-src]][bundle-href]
6
6
  [![JSDocs][jsdocs-src]][jsdocs-href]
7
7
 
8
- Prefer early return pattern to clean if else statement
8
+ Hyoban extended ESLint rules.
9
9
 
10
10
  <!-- Badges -->
11
11
 
package/dist/index.cjs CHANGED
@@ -2,10 +2,55 @@ Object.defineProperty(exports, '__esModule', { value: true });
2
2
 
3
3
  var utils = require('@typescript-eslint/utils');
4
4
 
5
- var version = "0.2.8";
5
+ var version = "0.3.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: 'jsx-attribute-spacing',
11
+ meta: {
12
+ type: 'layout',
13
+ fixable: 'whitespace',
14
+ docs: {
15
+ description: 'Enforce consistent spacing around JSX attributes'
16
+ },
17
+ messages: {
18
+ jsxAttributeSpacing: 'Expected space before and after JSX attribute'
19
+ },
20
+ schema: []
21
+ },
22
+ defaultOptions: [],
23
+ create (context) {
24
+ return {
25
+ JSXOpeningElement (node) {
26
+ const { attributes } = node;
27
+ if (attributes.length <= 1) return;
28
+ for (const [index, attribute] of attributes.entries()){
29
+ const nextAttribute = attributes[index + 1];
30
+ if (!nextAttribute) break;
31
+ const isSameLine = attribute.loc.end.line === nextAttribute.loc.start.line;
32
+ if (!isSameLine) continue;
33
+ const { range } = attribute;
34
+ const nextRange = nextAttribute.range;
35
+ const spaceBetween = nextRange[0] - range[1];
36
+ if (spaceBetween !== 1) {
37
+ context.report({
38
+ node: nextAttribute,
39
+ fix (fixer) {
40
+ return fixer.replaceTextRange([
41
+ range[1],
42
+ nextRange[0]
43
+ ], ' ');
44
+ },
45
+ messageId: 'jsxAttributeSpacing'
46
+ });
47
+ }
48
+ }
49
+ }
50
+ };
51
+ }
52
+ });
53
+
9
54
  const expressionTypesNoCheck = new Set([
10
55
  utils.AST_NODE_TYPES.ConditionalExpression,
11
56
  utils.AST_NODE_TYPES.JSXElement,
@@ -116,7 +161,8 @@ var index = {
116
161
  },
117
162
  rules: {
118
163
  'prefer-early-return': rule,
119
- 'no-extra-space-jsx-expression': rule$1
164
+ 'no-extra-space-jsx-expression': rule$1,
165
+ 'jsx-attribute-spacing': rule$2
120
166
  }
121
167
  };
122
168
 
package/dist/index.d.cts CHANGED
@@ -8,6 +8,7 @@ declare const _default: {
8
8
  rules: {
9
9
  'prefer-early-return': _typescript_eslint_utils_ts_eslint.RuleModule<"preferEarlyReturn", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
10
10
  'no-extra-space-jsx-expression': _typescript_eslint_utils_ts_eslint.RuleModule<"noExtraSpaceJsxExpression", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
11
+ 'jsx-attribute-spacing': _typescript_eslint_utils_ts_eslint.RuleModule<"jsxAttributeSpacing", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
11
12
  };
12
13
  };
13
14
 
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ declare const _default: {
8
8
  rules: {
9
9
  'prefer-early-return': _typescript_eslint_utils_ts_eslint.RuleModule<"preferEarlyReturn", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
10
10
  'no-extra-space-jsx-expression': _typescript_eslint_utils_ts_eslint.RuleModule<"noExtraSpaceJsxExpression", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
11
+ 'jsx-attribute-spacing': _typescript_eslint_utils_ts_eslint.RuleModule<"jsxAttributeSpacing", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
11
12
  };
12
13
  };
13
14
 
package/dist/index.js CHANGED
@@ -1,9 +1,54 @@
1
1
  import { ESLintUtils, AST_NODE_TYPES } from '@typescript-eslint/utils';
2
2
 
3
- var version = "0.2.8";
3
+ var version = "0.3.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: 'jsx-attribute-spacing',
9
+ meta: {
10
+ type: 'layout',
11
+ fixable: 'whitespace',
12
+ docs: {
13
+ description: 'Enforce consistent spacing around JSX attributes'
14
+ },
15
+ messages: {
16
+ jsxAttributeSpacing: 'Expected space before and after JSX attribute'
17
+ },
18
+ schema: []
19
+ },
20
+ defaultOptions: [],
21
+ create (context) {
22
+ return {
23
+ JSXOpeningElement (node) {
24
+ const { attributes } = node;
25
+ if (attributes.length <= 1) return;
26
+ for (const [index, attribute] of attributes.entries()){
27
+ const nextAttribute = attributes[index + 1];
28
+ if (!nextAttribute) break;
29
+ const isSameLine = attribute.loc.end.line === nextAttribute.loc.start.line;
30
+ if (!isSameLine) continue;
31
+ const { range } = attribute;
32
+ const nextRange = nextAttribute.range;
33
+ const spaceBetween = nextRange[0] - range[1];
34
+ if (spaceBetween !== 1) {
35
+ context.report({
36
+ node: nextAttribute,
37
+ fix (fixer) {
38
+ return fixer.replaceTextRange([
39
+ range[1],
40
+ nextRange[0]
41
+ ], ' ');
42
+ },
43
+ messageId: 'jsxAttributeSpacing'
44
+ });
45
+ }
46
+ }
47
+ }
48
+ };
49
+ }
50
+ });
51
+
7
52
  const expressionTypesNoCheck = new Set([
8
53
  AST_NODE_TYPES.ConditionalExpression,
9
54
  AST_NODE_TYPES.JSXElement,
@@ -114,7 +159,8 @@ var index = {
114
159
  },
115
160
  rules: {
116
161
  'prefer-early-return': rule,
117
- 'no-extra-space-jsx-expression': rule$1
162
+ 'no-extra-space-jsx-expression': rule$1,
163
+ 'jsx-attribute-spacing': rule$2
118
164
  }
119
165
  };
120
166
 
package/package.json CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "name": "eslint-plugin-hyoban",
3
- "version": "0.2.8",
3
+ "type": "module",
4
+ "version": "0.3.0",
4
5
  "description": "Hyoban extended ESLint rules.",
5
- "keywords": [],
6
+ "author": {
7
+ "name": "hyoban",
8
+ "url": "https://github.com/hyoban"
9
+ },
10
+ "license": "MIT",
6
11
  "homepage": "https://github.com/hyoban/eslint-plugin-hyoban#readme",
7
- "bugs": "https://github.com/hyoban/eslint-plugin-hyoban/issues",
8
12
  "repository": {
9
13
  "type": "git",
10
14
  "url": "git+https://github.com/hyoban/eslint-plugin-hyoban.git"
11
15
  },
12
- "license": "MIT",
13
- "author": {
14
- "name": "hyoban",
15
- "url": "https://github.com/hyoban"
16
- },
16
+ "bugs": "https://github.com/hyoban/eslint-plugin-hyoban/issues",
17
+ "keywords": [],
17
18
  "sideEffects": false,
18
- "type": "module",
19
19
  "exports": {
20
20
  ".": {
21
21
  "import": {
@@ -42,32 +42,27 @@
42
42
  "files": [
43
43
  "dist"
44
44
  ],
45
+ "peerDependencies": {
46
+ "eslint": "*"
47
+ },
45
48
  "dependencies": {
46
- "@typescript-eslint/utils": "^7.6.0"
49
+ "@typescript-eslint/utils": "^7.8.0"
47
50
  },
48
51
  "devDependencies": {
49
- "@ianvs/prettier-plugin-sort-imports": "^4.2.1",
50
- "@types/node": "^20.12.7",
51
- "@typescript-eslint/rule-tester": "^7.6.0",
52
- "bunchee": "^5.1.2",
53
- "dedent": "^1.5.3",
54
- "eslint": "8.57.0",
55
- "eslint-config-hyoban": "^0.7.1",
56
- "prettier": "^3.2.5",
57
- "prettier-plugin-curly": "^0.2.1",
58
- "prettier-plugin-packagejson": "^2.4.14",
52
+ "@types/node": "^20.12.10",
53
+ "@typescript-eslint/parser": "^7.8.0",
54
+ "bunchee": "^5.1.5",
55
+ "eslint": "^9.2.0",
56
+ "eslint-config-hyoban": "^2.2.5",
57
+ "eslint-vitest-rule-tester": "^0.2.1",
59
58
  "typescript": "^5.4.5",
60
- "vitest": "^1.4.0"
61
- },
62
- "peerDependencies": {
63
- "eslint": "*"
59
+ "vitest": "^1.6.0"
64
60
  },
65
- "packageManager": "pnpm@8.15.6",
66
61
  "scripts": {
67
62
  "build": "bunchee",
68
63
  "dev": "bunchee -w",
69
- "lint": "prettier --check . && eslint .",
70
- "lint:fix": "prettier --write . && eslint . --fix",
64
+ "lint": "eslint .",
65
+ "lint:fix": "eslint . --fix",
71
66
  "test": "vitest",
72
67
  "typecheck": "tsc"
73
68
  }