@virmator/lint 14.29.1 → 14.30.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.
@@ -12,6 +12,7 @@ import noRawDateRule from '../src/rules/no-raw-date.lint.js';
12
12
  import noReadonlyPrimitiveRule from '../src/rules/no-readonly-primitive.lint.js';
13
13
  import noRelativeImportOutsidePackageRule from '../src/rules/no-relative-import-outside-package.lint.js';
14
14
  import noShouldInTestDescriptionRule from '../src/rules/no-should-in-test-description.lint.js';
15
+ import noSwitchRule from '../src/rules/no-switch.lint.js';
15
16
  import noUnderscoreVariableRule from '../src/rules/no-underscore-variable.lint.js';
16
17
  import preferArrowObjectBlockBodyRule from '../src/rules/prefer-arrow-object-block-body.lint.js';
17
18
  import preferEnsureErrorRule from '../src/rules/prefer-ensure-error.lint.js';
@@ -80,6 +81,7 @@ export function defineEslintConfig(repoDir: string) {
80
81
  'no-readonly-primitive': noReadonlyPrimitiveRule,
81
82
  'no-relative-import-outside-package': noRelativeImportOutsidePackageRule,
82
83
  'no-should-in-test-description': noShouldInTestDescriptionRule,
84
+ 'no-switch': noSwitchRule,
83
85
  'no-underscore-variable': noUnderscoreVariableRule,
84
86
  'prefer-arrow-object-block-body': preferArrowObjectBlockBodyRule,
85
87
  'prefer-ensure-error': preferEnsureErrorRule,
@@ -166,7 +168,6 @@ export function defineEslintConfig(repoDir: string) {
166
168
  'unicorn/no-useless-fallback-in-spread': 'error',
167
169
  'unicorn/no-useless-length-check': 'error',
168
170
  'unicorn/no-useless-spread': 'error',
169
- 'unicorn/no-useless-switch-case': 'error',
170
171
  'unicorn/no-zero-fractions': 'error',
171
172
  'unicorn/numeric-separators-style': 'error',
172
173
  'unicorn/prefer-array-find': 'error',
@@ -202,6 +203,7 @@ export function defineEslintConfig(repoDir: string) {
202
203
  '@virmator/no-readonly-primitive': 'error',
203
204
  '@virmator/no-relative-import-outside-package': 'error',
204
205
  '@virmator/no-should-in-test-description': 'error',
206
+ '@virmator/no-switch': 'error',
205
207
  '@virmator/no-underscore-variable': 'error',
206
208
  '@virmator/prefer-arrow-object-block-body': 'error',
207
209
  '@virmator/prefer-ensure-error': 'error',
@@ -0,0 +1,3 @@
1
+ import { type Rule } from 'eslint';
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -0,0 +1,22 @@
1
+ const rule = {
2
+ meta: {
3
+ type: 'suggestion',
4
+ messages: {
5
+ noSwitch: 'Do not use `switch`. Use a `Record` object mapping (for enum or other fixed key sets) or an if/else chain instead.',
6
+ },
7
+ schema: [],
8
+ },
9
+ create(context) {
10
+ return {
11
+ SwitchStatement(node) {
12
+ context.report({
13
+ node,
14
+ /** Report just the `switch` keyword so a long switch body isn't all underlined. */
15
+ loc: context.sourceCode.getFirstToken(node)?.loc ?? node.loc ?? undefined,
16
+ messageId: 'noSwitch',
17
+ });
18
+ },
19
+ };
20
+ },
21
+ };
22
+ export default rule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@virmator/lint",
3
- "version": "14.29.1",
3
+ "version": "14.30.0",
4
4
  "description": "Default ESLint linting plugin for virmator.",
5
5
  "keywords": [
6
6
  "virmator",
@@ -35,7 +35,7 @@
35
35
  "@augment-vir/assert": "^32.1.0",
36
36
  "@augment-vir/common": "^32.1.0",
37
37
  "@augment-vir/node": "^32.1.0",
38
- "@virmator/core": "^14.29.1",
38
+ "@virmator/core": "^14.30.0",
39
39
  "globals": "^17.7.0",
40
40
  "jiti": "^2.7.0",
41
41
  "mri": "^1.2.0"
@@ -0,0 +1,27 @@
1
+ import {type Rule} from 'eslint';
2
+ import type {SwitchStatement} from 'estree';
3
+
4
+ const rule: Rule.RuleModule = {
5
+ meta: {
6
+ type: 'suggestion',
7
+ messages: {
8
+ noSwitch:
9
+ 'Do not use `switch`. Use a `Record` object mapping (for enum or other fixed key sets) or an if/else chain instead.',
10
+ },
11
+ schema: [],
12
+ },
13
+ create(context) {
14
+ return {
15
+ SwitchStatement(node: SwitchStatement & Rule.NodeParentExtension) {
16
+ context.report({
17
+ node,
18
+ /** Report just the `switch` keyword so a long switch body isn't all underlined. */
19
+ loc: context.sourceCode.getFirstToken(node)?.loc ?? node.loc ?? undefined,
20
+ messageId: 'noSwitch',
21
+ });
22
+ },
23
+ };
24
+ },
25
+ };
26
+
27
+ export default rule;