@virmator/lint 14.37.2 → 14.39.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.
@@ -9,6 +9,7 @@ import tsEslint from 'typescript-eslint';
9
9
  import allowedFileExtensionsRule from '../src/rules/allowed-file-extensions.lint.js';
10
10
  import assertionsInTestsRule from '../src/rules/assertions-in-tests.lint.js';
11
11
  import errorNameAsClassFieldRule from '../src/rules/error-name-as-class-field.lint.js';
12
+ import noCheckIsObjectRule from '../src/rules/no-check-is-object.lint.js';
12
13
  import noJsdocCategoryRule from '../src/rules/no-jsdoc-category.lint.js';
13
14
  import noRawDateRule from '../src/rules/no-raw-date.lint.js';
14
15
  import noReadonlyPrimitiveRule from '../src/rules/no-readonly-primitive.lint.js';
@@ -50,13 +51,16 @@ export const defaultAllowedFileExtensions = [
50
51
  '.element.ts',
51
52
  '.endpoint.implementation.ts',
52
53
  '.endpoint.ts',
54
+ '.endpoints.ts',
53
55
  '.entity.ts',
54
56
  '.error.ts',
55
57
  '.event.ts',
56
58
  '.icon.ts',
59
+ '.implementation.ts',
57
60
  '.js',
58
61
  '.mock.script.ts',
59
62
  '.mod.ts',
63
+ '.observable.ts',
60
64
  '.script.ts',
61
65
  '.test.e2e.ts',
62
66
  '.test.node.ts',
@@ -121,6 +125,7 @@ export function defineEslintConfig(repoDir: string) {
121
125
  'assertions-in-tests': assertionsInTestsRule,
122
126
  'error-name-as-class-field': errorNameAsClassFieldRule,
123
127
  'allowed-file-extensions': allowedFileExtensionsRule,
128
+ 'no-check-is-object': noCheckIsObjectRule,
124
129
  'no-jsdoc-category': noJsdocCategoryRule,
125
130
  'no-raw-date': noRawDateRule,
126
131
  'no-readonly-primitive': noReadonlyPrimitiveRule,
@@ -259,6 +264,7 @@ export function defineEslintConfig(repoDir: string) {
259
264
  * are useful in published packages. Consumers that do not use Typedoc enable it
260
265
  * themselves.
261
266
  */
267
+ '@virmator/no-check-is-object': 'error',
262
268
  '@virmator/no-raw-date': 'error',
263
269
  '@virmator/no-readonly-primitive': 'error',
264
270
  '@virmator/no-relative-import-outside-package': 'error',
@@ -333,25 +339,25 @@ export function defineEslintConfig(repoDir: string) {
333
339
  next: 'import',
334
340
  },
335
341
  ],
336
- '@stylistic/object-curly-newline': [
342
+ '@stylistic/list-style': [
337
343
  'error',
338
344
  {
339
- ObjectExpression: {
340
- multiline: true,
341
- minProperties: 1,
342
- consistent: true,
345
+ singleLine: {
346
+ spacing: 'never',
343
347
  },
344
- ObjectPattern: {
345
- multiline: true,
346
- consistent: true,
347
- },
348
- ImportDeclaration: {
349
- multiline: true,
350
- consistent: true,
351
- },
352
- ExportDeclaration: {
353
- multiline: true,
354
- consistent: true,
348
+ overrides: {
349
+ '()': 'off',
350
+ '[]': 'off',
351
+ '{}': 'off',
352
+ '<>': 'off',
353
+ ObjectExpression: {
354
+ singleLine: {
355
+ maxItems: 0,
356
+ },
357
+ },
358
+ ObjectPattern: {},
359
+ ImportDeclaration: {},
360
+ ExportNamedDeclaration: {},
355
361
  },
356
362
  },
357
363
  ],
@@ -0,0 +1,3 @@
1
+ import { type Rule } from 'eslint';
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -0,0 +1,57 @@
1
+ const equalityOperators = [
2
+ '===',
3
+ '==',
4
+ '!==',
5
+ '!=',
6
+ ];
7
+ function isTypeof(node) {
8
+ return node.type === 'UnaryExpression' && node.operator === 'typeof';
9
+ }
10
+ function isObjectLiteral(node) {
11
+ return node.type === 'Literal' && node.value === 'object';
12
+ }
13
+ const rule = {
14
+ meta: {
15
+ type: 'suggestion',
16
+ messages: {
17
+ noCheckIsObject: 'Do not use `check.isObject`. Define the expected shape with `defineShape` and validate it with object-shape-tester (e.g. `checkValidShape`) instead.',
18
+ noTypeofObject: "Do not compare `typeof` to `'object'`. Define the expected shape with `defineShape` and validate it with object-shape-tester (e.g. `checkValidShape`) instead.",
19
+ },
20
+ schema: [],
21
+ },
22
+ create(context) {
23
+ return {
24
+ BinaryExpression(node) {
25
+ if (!equalityOperators.includes(node.operator)) {
26
+ return;
27
+ }
28
+ const isTypeofObject = (isTypeof(node.left) && isObjectLiteral(node.right)) ||
29
+ (isObjectLiteral(node.left) && isTypeof(node.right));
30
+ if (!isTypeofObject) {
31
+ return;
32
+ }
33
+ context.report({
34
+ node,
35
+ messageId: 'noTypeofObject',
36
+ });
37
+ },
38
+ MemberExpression(node) {
39
+ const isCheckObject = node.object.type === 'Identifier' && node.object.name === 'check';
40
+ const isIsObjectProperty = (!node.computed &&
41
+ node.property.type === 'Identifier' &&
42
+ node.property.name === 'isObject') ||
43
+ (node.computed &&
44
+ node.property.type === 'Literal' &&
45
+ node.property.value === 'isObject');
46
+ if (!isCheckObject || !isIsObjectProperty) {
47
+ return;
48
+ }
49
+ context.report({
50
+ node,
51
+ messageId: 'noCheckIsObject',
52
+ });
53
+ },
54
+ };
55
+ },
56
+ };
57
+ export default rule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@virmator/lint",
3
- "version": "14.37.2",
3
+ "version": "14.39.0",
4
4
  "description": "Default ESLint linting plugin for virmator.",
5
5
  "keywords": [
6
6
  "virmator",
@@ -32,32 +32,32 @@
32
32
  "test:update": "npm test update"
33
33
  },
34
34
  "dependencies": {
35
- "@augment-vir/assert": "^32.5.0",
36
- "@augment-vir/common": "^32.5.0",
37
- "@augment-vir/node": "^32.5.0",
38
- "@virmator/core": "^14.37.2",
39
- "globals": "^17.13.0",
35
+ "@augment-vir/assert": "^32.7.1",
36
+ "@augment-vir/common": "^32.7.1",
37
+ "@augment-vir/node": "^32.7.1",
38
+ "@virmator/core": "^14.39.0",
39
+ "globals": "^17.14.0",
40
40
  "jiti": "^2.7.0",
41
41
  "mri": "^1.2.0"
42
42
  },
43
43
  "devDependencies": {
44
- "@augment-vir/test": "^32.5.0",
44
+ "@augment-vir/test": "^32.7.1",
45
45
  "@eslint/js": "10.0.1",
46
- "@stylistic/eslint-plugin": "^5.10.0",
46
+ "@stylistic/eslint-plugin": "^6.0.1",
47
47
  "@stylistic/eslint-plugin-ts": "^4.4.1",
48
- "@types/estree": "^1.0.9",
49
- "@types/node": "^26.6.3",
50
- "@typescript-eslint/eslint-plugin": "^8.71.0",
48
+ "@types/estree": "^1.0.10",
49
+ "@types/node": "^26.6.6",
50
+ "@typescript-eslint/eslint-plugin": "^8.73.0",
51
51
  "c8": "^12.0.0",
52
- "eslint": "^10.11.0",
52
+ "eslint": "^10.15.0",
53
53
  "eslint-config-prettier": "^10.1.8",
54
- "eslint-plugin-jsdoc": "^65.0.1",
55
- "eslint-plugin-playwright": "^2.12.0",
56
- "eslint-plugin-prettier": "^5.5.6",
54
+ "eslint-plugin-jsdoc": "^65.5.1",
55
+ "eslint-plugin-playwright": "^2.12.2",
56
+ "eslint-plugin-prettier": "^5.5.7",
57
57
  "eslint-plugin-sonarjs": "^4.2.2",
58
- "eslint-plugin-unicorn": "^76.0.0",
58
+ "eslint-plugin-unicorn": "^80.0.0",
59
59
  "istanbul-smart-text-reporter": "^1.1.5",
60
- "typescript-eslint": "^8.71.0"
60
+ "typescript-eslint": "^8.73.0"
61
61
  },
62
62
  "engines": {
63
63
  "node": ">=22"
@@ -0,0 +1,74 @@
1
+ import {type Rule} from 'eslint';
2
+ import type {BinaryExpression, Expression, MemberExpression, PrivateIdentifier} from 'estree';
3
+
4
+ const equalityOperators: ReadonlyArray<BinaryExpression['operator']> = [
5
+ '===',
6
+ '==',
7
+ '!==',
8
+ '!=',
9
+ ];
10
+
11
+ function isTypeof(node: Readonly<Expression | PrivateIdentifier>) {
12
+ return node.type === 'UnaryExpression' && node.operator === 'typeof';
13
+ }
14
+
15
+ function isObjectLiteral(node: Readonly<Expression | PrivateIdentifier>) {
16
+ return node.type === 'Literal' && node.value === 'object';
17
+ }
18
+
19
+ const rule: Rule.RuleModule = {
20
+ meta: {
21
+ type: 'suggestion',
22
+ messages: {
23
+ noCheckIsObject:
24
+ 'Do not use `check.isObject`. Define the expected shape with `defineShape` and validate it with object-shape-tester (e.g. `checkValidShape`) instead.',
25
+ noTypeofObject:
26
+ "Do not compare `typeof` to `'object'`. Define the expected shape with `defineShape` and validate it with object-shape-tester (e.g. `checkValidShape`) instead.",
27
+ },
28
+ schema: [],
29
+ },
30
+ create(context) {
31
+ return {
32
+ BinaryExpression(node: BinaryExpression & Rule.NodeParentExtension) {
33
+ if (!equalityOperators.includes(node.operator)) {
34
+ return;
35
+ }
36
+
37
+ const isTypeofObject =
38
+ (isTypeof(node.left) && isObjectLiteral(node.right)) ||
39
+ (isObjectLiteral(node.left) && isTypeof(node.right));
40
+
41
+ if (!isTypeofObject) {
42
+ return;
43
+ }
44
+
45
+ context.report({
46
+ node,
47
+ messageId: 'noTypeofObject',
48
+ });
49
+ },
50
+ MemberExpression(node: MemberExpression & Rule.NodeParentExtension) {
51
+ const isCheckObject =
52
+ node.object.type === 'Identifier' && node.object.name === 'check';
53
+ const isIsObjectProperty =
54
+ (!node.computed &&
55
+ node.property.type === 'Identifier' &&
56
+ node.property.name === 'isObject') ||
57
+ (node.computed &&
58
+ node.property.type === 'Literal' &&
59
+ node.property.value === 'isObject');
60
+
61
+ if (!isCheckObject || !isIsObjectProperty) {
62
+ return;
63
+ }
64
+
65
+ context.report({
66
+ node,
67
+ messageId: 'noCheckIsObject',
68
+ });
69
+ },
70
+ };
71
+ },
72
+ };
73
+
74
+ export default rule;