eslint-config-matsuri 1.5.0 → 1.6.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.
package/index.js CHANGED
@@ -15,7 +15,7 @@ const config = {
15
15
  extends: ["eslint:recommended"],
16
16
  plugins: ["sort-imports-es6-autofix", "rulesdir"],
17
17
  rules: {
18
- "rulesdir/naming-convention": "error",
18
+ "rulesdir/naming-convention": ["error", { fixable: false }],
19
19
 
20
20
  "no-console": ["error", { allow: ["error"] }],
21
21
  eqeqeq: ["error", "always"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-config-matsuri",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -26,7 +26,7 @@
26
26
  "typescript": "4.9.5"
27
27
  },
28
28
  "dependencies": {
29
- "@typescript-eslint/eslint-plugin": "5.54.0",
29
+ "@typescript-eslint/eslint-plugin": "5.57.0",
30
30
  "@typescript-eslint/parser": "5.52.0",
31
31
  "eslint-config-prettier": "8.6.0",
32
32
  "eslint-plugin-css-reorder": "0.5.1",
@@ -49,14 +49,20 @@ const trimUnderscore = (name, leadingUnderscore, trailingUnderscore) => {
49
49
  return name;
50
50
  };
51
51
 
52
- const reportValidity = (
53
- context,
54
- node,
55
- format,
56
- fix,
57
- leadingUnderscore,
58
- trailingUnderscore
59
- ) => {
52
+ /**
53
+ * @typedef Option
54
+ * @property {string[]} format
55
+ * @property {string} fix
56
+ * @property {string} leadingUnderscore
57
+ * @property {string} trailingUnderscore
58
+ */
59
+
60
+ /**
61
+ * @param {Option} option
62
+ * @param {boolean} fixable
63
+ */
64
+ const reportValidity = (context, node, option, fixable) => {
65
+ const { format, fix, leadingUnderscore, trailingUnderscore } = option;
60
66
  if (node.id === null) {
61
67
  return;
62
68
  }
@@ -73,20 +79,25 @@ const reportValidity = (
73
79
  context.report({
74
80
  node,
75
81
  message: `${node.id.name} must be ${format.join(" or ")}`,
76
- fix: (fixer) => {
77
- switch (fix) {
78
- case "camelCase": {
79
- return fixer.replaceText(node.id, toCamelCase(node.id.name));
80
- }
81
- default: {
82
- return fixer.replaceText(node.id, node.id.name);
82
+ fix: fixable
83
+ ? (fixer) => {
84
+ switch (fix) {
85
+ case "camelCase": {
86
+ return fixer.replaceText(node.id, toCamelCase(node.id.name));
87
+ }
88
+ default: {
89
+ return fixer.replaceText(node.id, node.id.name);
90
+ }
91
+ }
83
92
  }
84
- }
85
- },
93
+ : null,
86
94
  });
87
95
  }
88
96
  };
89
97
 
98
+ /**
99
+ * @type {Object.<string, Option>}
100
+ */
90
101
  const options = {
91
102
  validable: {
92
103
  format: ["camelCase", "UPPER_CASE"],
@@ -109,49 +120,24 @@ const rule = {
109
120
  meta: {
110
121
  type: "problem",
111
122
  fixable: "code",
123
+ hasSuggestions: true
112
124
  },
113
125
  create: (context) => {
126
+ const fixable = context.options[0]?.fixable ?? false;
127
+
114
128
  return {
115
129
  VariableDeclarator: (node) => {
116
130
  if (node.init?.type === "ArrowFunctionExpression") {
117
- reportValidity(
118
- context,
119
- node,
120
- options.function.format,
121
- options.function.fix,
122
- options.function.leadingUnderscore,
123
- options.function.trailingUnderscore
124
- );
131
+ reportValidity(context, node, options.function, fixable);
125
132
  } else {
126
- reportValidity(
127
- context,
128
- node,
129
- options.validable.format,
130
- options.validable.fix,
131
- options.validable.leadingUnderscore,
132
- options.validable.trailingUnderscore
133
- );
133
+ reportValidity(context, node, options.validable, fixable);
134
134
  }
135
135
  },
136
136
  FunctionDeclaration: (node) => {
137
- reportValidity(
138
- context,
139
- node,
140
- options.function.format,
141
- options.function.fix,
142
- options.function.leadingUnderscore,
143
- options.function.trailingUnderscore
144
- );
137
+ reportValidity(context, node, options.function, fixable);
145
138
  },
146
139
  FunctionExpression: (node) => {
147
- reportValidity(
148
- context,
149
- node,
150
- options.function.format,
151
- options.function.fix,
152
- options.function.leadingUnderscore,
153
- options.function.trailingUnderscore
154
- );
140
+ reportValidity(context, node, options.function, fixable);
155
141
  },
156
142
  };
157
143
  },