eslint-config-matsuri 1.4.2-alpha-59d7419.0 → 1.6.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/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const rulesDirPlugin = require("eslint-plugin-rulesdir");
2
- rulesDirPlugin.RULES_DIR = "./rules";
2
+ rulesDirPlugin.RULES_DIR = __dirname + "/rules";
3
3
 
4
4
  /** @type {import('eslint').Linter.BaseConfig} */
5
5
  const config = {
@@ -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.4.2-alpha-59d7419.0",
3
+ "version": "1.6.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -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"],
@@ -111,47 +122,21 @@ const rule = {
111
122
  fixable: "code",
112
123
  },
113
124
  create: (context) => {
125
+ const fixable = context.options[0]?.fixable ?? false;
126
+
114
127
  return {
115
128
  VariableDeclarator: (node) => {
116
- 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
- );
129
+ if (node.init?.type === "ArrowFunctionExpression") {
130
+ reportValidity(context, node, options.function, fixable);
125
131
  } else {
126
- reportValidity(
127
- context,
128
- node,
129
- options.validable.format,
130
- options.validable.fix,
131
- options.validable.leadingUnderscore,
132
- options.validable.trailingUnderscore
133
- );
132
+ reportValidity(context, node, options.validable, fixable);
134
133
  }
135
134
  },
136
135
  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
- );
136
+ reportValidity(context, node, options.function, fixable);
145
137
  },
146
138
  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
- );
139
+ reportValidity(context, node, options.function, fixable);
155
140
  },
156
141
  };
157
142
  },