eslint-plugin-th-rules 3.1.6 → 3.1.8

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.
@@ -1 +1 @@
1
- {"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../../src/configs/core/typescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE1E,eAAO,MAAM,cAAc,EAAE,iBAAiB,EAmB7C,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../../../src/configs/core/typescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE1E,eAAO,MAAM,cAAc,EAAE,iBAAiB,EAoB7C,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -2,6 +2,7 @@ import { configs as ts } from 'typescript-eslint';
2
2
  export const coreTypescript = [
3
3
  ...ts.strictTypeChecked,
4
4
  ...ts.stylisticTypeChecked,
5
+ ...ts.recommendedTypeChecked,
5
6
  {
6
7
  name: 'th-rules/core-typescript-overrides',
7
8
  rules: {
@@ -1 +1 @@
1
- {"version":3,"file":"schemas-in-schemas-file.d.ts","sourceRoot":"","sources":["../../src/rules/schemas-in-schemas-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAAiB,MAAM,0BAA0B,CAAC;AAEtF,QAAA,MAAM,oBAAoB;;;;;;CAyJxB,CAAC;AACH,eAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"schemas-in-schemas-file.d.ts","sourceRoot":"","sources":["../../src/rules/schemas-in-schemas-file.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,WAAW,EAAiB,MAAM,0BAA0B,CAAC;AAEtF,QAAA,MAAM,oBAAoB;;;;;;CAmIxB,CAAC;AAEH,eAAe,oBAAoB,CAAC"}
@@ -1,3 +1,5 @@
1
+ /* eslint-disable @typescript-eslint/no-unnecessary-condition */
2
+ /* eslint-disable new-cap */
1
3
  import { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils';
2
4
  const schemasInSchemasFile = ESLintUtils.RuleCreator(() => 'https://github.com/tomerh2001/eslint-plugin-th-rules/blob/main/docs/rules/schemas-in-schemas-file.md')({
3
5
  name: 'schemas-in-schemas-file',
@@ -13,7 +15,6 @@ const schemasInSchemasFile = ESLintUtils.RuleCreator(() => 'https://github.com/t
13
15
  allowedSuffixes: {
14
16
  type: 'array',
15
17
  items: { type: 'string', minLength: 1 },
16
- minItems: 1,
17
18
  },
18
19
  onlyWhenAssigned: { type: 'boolean' },
19
20
  allowInTests: { type: 'boolean' },
@@ -32,25 +33,24 @@ const schemasInSchemasFile = ESLintUtils.RuleCreator(() => 'https://github.com/t
32
33
  allowInTests: false,
33
34
  },
34
35
  ],
35
- create(context, [options]) {
36
- const allowedSuffixes = options.allowedSuffixes && options.allowedSuffixes.length > 0 ? options.allowedSuffixes : ['.schemas.ts'];
37
- const onlyWhenAssigned = options.onlyWhenAssigned ?? false;
38
- const allowInTests = options.allowInTests ?? false;
36
+ create(context, [rawOptions]) {
37
+ const options = {
38
+ allowedSuffixes: rawOptions?.allowedSuffixes ?? ['.schemas.ts'],
39
+ onlyWhenAssigned: rawOptions?.onlyWhenAssigned ?? false,
40
+ allowInTests: rawOptions?.allowInTests ?? false,
41
+ };
39
42
  const zodIdentifiers = new Set();
40
43
  function filenameAllowed(filename) {
41
44
  if (!filename || filename === '<input>') {
42
45
  return false;
43
46
  }
44
- if (allowInTests && /\.(test|spec)\.[jt]sx?$/.test(filename)) {
47
+ if (options.allowInTests && /\.(test|spec)\.[jt]sx?$/.test(filename)) {
45
48
  return true;
46
49
  }
47
- return allowedSuffixes.some((suffix) => filename.endsWith(suffix));
48
- }
49
- function isZodModuleImport(node) {
50
- return node.source.value === 'zod';
50
+ return options.allowedSuffixes.some((suffix) => filename.endsWith(suffix));
51
51
  }
52
52
  function collectZodIdentifiersFromImport(node) {
53
- if (!isZodModuleImport(node)) {
53
+ if (node.source.value !== 'zod') {
54
54
  return;
55
55
  }
56
56
  for (const spec of node.specifiers) {
@@ -64,53 +64,37 @@ const schemasInSchemasFile = ESLintUtils.RuleCreator(() => 'https://github.com/t
64
64
  }
65
65
  function isZodBuilderCall(node) {
66
66
  const { callee } = node;
67
- if (callee.type !== AST_NODE_TYPES.MemberExpression || callee.computed) {
68
- return false;
69
- }
70
- const { object } = callee;
71
- const { property } = callee;
72
- return object.type === AST_NODE_TYPES.Identifier && zodIdentifiers.has(object.name) && property.type === AST_NODE_TYPES.Identifier;
67
+ return callee.type === AST_NODE_TYPES.MemberExpression && !callee.computed && callee.object.type === AST_NODE_TYPES.Identifier && zodIdentifiers.has(callee.object.name);
73
68
  }
74
69
  function isZodChainedBuilderCall(node) {
75
- const { callee } = node;
76
- if (callee.type !== AST_NODE_TYPES.MemberExpression || callee.computed) {
77
- return false;
78
- }
79
- let current = callee.object;
80
- while (current.type === AST_NODE_TYPES.MemberExpression && !current.computed) {
70
+ let current = node.callee;
71
+ while (current?.type === AST_NODE_TYPES.MemberExpression && !current.computed) {
81
72
  current = current.object;
82
73
  }
83
- return current.type === AST_NODE_TYPES.Identifier && zodIdentifiers.has(current.name);
74
+ return current?.type === AST_NODE_TYPES.Identifier && zodIdentifiers.has(current.name);
84
75
  }
85
- function getAssignmentTargetName(callNode) {
86
- const { parent } = callNode;
87
- if (parent.type === AST_NODE_TYPES.VariableDeclarator && parent.id.type === AST_NODE_TYPES.Identifier) {
88
- return parent.id.name;
89
- }
90
- if (parent.type === AST_NODE_TYPES.AssignmentExpression && parent.left.type === AST_NODE_TYPES.Identifier) {
91
- return parent.left.name;
92
- }
76
+ function getAssignmentTarget(node) {
77
+ const { parent } = node;
78
+ return ((parent?.type === AST_NODE_TYPES.VariableDeclarator && parent.id.type === AST_NODE_TYPES.Identifier) ||
79
+ (parent?.type === AST_NODE_TYPES.AssignmentExpression && parent.left.type === AST_NODE_TYPES.Identifier));
93
80
  }
94
81
  function report(node) {
95
82
  if (filenameAllowed(context.filename)) {
96
83
  return;
97
84
  }
98
- const targetName = getAssignmentTargetName(node);
99
- if (onlyWhenAssigned && !targetName) {
85
+ if (options.onlyWhenAssigned && !getAssignmentTarget(node)) {
100
86
  return;
101
87
  }
102
88
  context.report({
103
89
  node,
104
90
  messageId: 'moveSchema',
105
91
  data: {
106
- suffixes: allowedSuffixes.join(' or '),
92
+ suffixes: options.allowedSuffixes.join(' or ') || '.schemas.ts',
107
93
  },
108
94
  });
109
95
  }
110
96
  return {
111
- ImportDeclaration(node) {
112
- collectZodIdentifiersFromImport(node);
113
- },
97
+ ImportDeclaration: collectZodIdentifiersFromImport,
114
98
  CallExpression(node) {
115
99
  if (zodIdentifiers.size === 0) {
116
100
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-th-rules",
3
- "version": "3.1.6",
3
+ "version": "3.1.8",
4
4
  "description": "A List of custom ESLint rules created by Tomer Horowitz",
5
5
  "keywords": [
6
6
  "eslint",
@@ -25,17 +25,15 @@
25
25
  "@babel/eslint-parser": "^7.28.6",
26
26
  "@eslint/eslintrc": "^3.3.3",
27
27
  "@leancodepl/resolve-eslint-flat-config": "^9.7.0",
28
- "@typescript-eslint/eslint-plugin": "^8.53.0",
29
- "@typescript-eslint/parser": "^8.53.0",
30
- "@typescript-eslint/rule-tester": "^8.53.0",
31
- "@typescript-eslint/utils": "^8.53.0",
32
28
  "eslint-config-jsdoc": "^15.4.0",
29
+ "eslint-config-prettier": "^10.1.8",
33
30
  "eslint-config-xo": "^0.49.0",
34
31
  "eslint-config-xo-react": "^0.29.0",
35
32
  "eslint-plugin-import": "^2.32.0",
36
33
  "eslint-plugin-jsdoc": "^62.0.0",
37
34
  "eslint-plugin-lodash": "^8.0.0",
38
35
  "eslint-plugin-n": "^17.23.2",
36
+ "eslint-plugin-prettier": "^5.5.5",
39
37
  "eslint-plugin-react": "^7.37.5",
40
38
  "eslint-plugin-react-hooks": "^7.0.1",
41
39
  "eslint-plugin-react-native": "^5.0.0",
@@ -45,7 +43,9 @@
45
43
  "globals": "^17.0.0",
46
44
  "lodash": "^4.17.21",
47
45
  "requireindex": "^1.2.0",
48
- "typescript-eslint": "^8.53.0"
46
+ "typescript": "^5.9.3",
47
+ "typescript-eslint": "^8.53.0",
48
+ "xo": "^1.2.3"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@codedependant/semantic-release-docker": "^5.1.1",
@@ -63,19 +63,19 @@
63
63
  "@types/node": "^25.0.9",
64
64
  "@types/requireindex": "^1.2.4",
65
65
  "@types/xo": "^0.39.9",
66
+ "@typescript-eslint/eslint-plugin": "8.53.0",
67
+ "@typescript-eslint/parser": "8.53.0",
68
+ "@typescript-eslint/rule-tester": "8.53.0",
69
+ "@typescript-eslint/utils": "8.53.0",
66
70
  "bun-types": "latest",
67
71
  "eslint": "^9.39.2",
68
- "eslint-config-prettier": "^10.1.8",
69
72
  "eslint-doc-generator": "^3.0.2",
70
- "eslint-plugin-prettier": "^5.5.5",
71
73
  "eslint-plugin-th-rules": "2.7.1",
72
74
  "jest": "^30.2.0",
73
75
  "mocha": "^11.7.5",
74
76
  "npm-run-all": "^4.1.5",
75
77
  "semantic-release": "^25.0.2",
76
- "ts-jest": "^29.4.6",
77
- "typescript": "^5.9.3",
78
- "xo": "^1.2.3"
78
+ "ts-jest": "^29.4.6"
79
79
  },
80
80
  "license": "ISC",
81
81
  "packageManager": "yarn@4.12.0"