eslint-plugin-th-rules 1.17.0 → 1.17.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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.17.1](https://github.com/tomerh2001/eslint-plugin-th-rules/compare/v1.17.0...v1.17.1) (2026-01-05)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * improve style file validation messages and simplify code structure ([5c165b4](https://github.com/tomerh2001/eslint-plugin-th-rules/commit/5c165b4fcbc103df752e7c56f988c725dae6a62c))
7
+
1
8
  # [1.17.0](https://github.com/tomerh2001/eslint-plugin-th-rules/compare/v1.16.0...v1.17.0) (2026-01-05)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-th-rules",
3
- "version": "1.17.0",
3
+ "version": "1.17.1",
4
4
  "description": "A List of custom ESLint rules created by Tomer Horowitz",
5
5
  "keywords": [
6
6
  "eslint",
@@ -10,19 +10,11 @@ const meta = {
10
10
  {
11
11
  type: 'object',
12
12
  properties: {
13
- /**
14
- * Allowed style file suffixes. Defaults:
15
- * [".styles.ts", ".styles.tsx"]
16
- */
17
13
  allowedSuffixes: {
18
14
  type: 'array',
19
15
  items: {type: 'string', minLength: 1},
20
16
  minItems: 1,
21
17
  },
22
-
23
- /**
24
- * If true, also flag `StyleSheet.compose(...)` (optional).
25
- */
26
18
  includeCompose: {type: 'boolean'},
27
19
  },
28
20
  additionalProperties: false,
@@ -30,7 +22,7 @@ const meta = {
30
22
  ],
31
23
  messages: {
32
24
  moveStyles:
33
- 'React-Native styles must be moved to a .styles.ts/.styles.tsx file (for example "{{filename}}.styles.ts").',
25
+ 'React-Native styles{{target}} must be defined in a dedicated styles file ({{suffixes}}). Current file: "{{filename}}".',
34
26
  },
35
27
  };
36
28
 
@@ -56,18 +48,62 @@ function create(context) {
56
48
  const object = callee.object;
57
49
  const property = callee.property;
58
50
 
59
- const isStyleSheet
60
- = object
61
- && object.type === 'Identifier'
62
- && object.name === 'StyleSheet';
51
+ return (
52
+ object?.type === 'Identifier'
53
+ && object.name === 'StyleSheet'
54
+ && !callee.computed
55
+ && property?.type === 'Identifier'
56
+ && property.name === memberName
57
+ );
58
+ }
59
+
60
+ /**
61
+ * Try to infer the “name” of the style object, e.g.:
62
+ * const styles = StyleSheet.create(...) -> "styles"
63
+ * styles = StyleSheet.create(...) -> "styles"
64
+ * exports.styles = StyleSheet.create(...) -> "exports.styles"
65
+ */
66
+ function getAssignmentTargetName(callNode) {
67
+ const p = callNode.parent;
68
+
69
+ if (p?.type === 'VariableDeclarator') {
70
+ const id = p.id;
71
+ if (id?.type === 'Identifier') {
72
+ return id.name;
73
+ }
74
+
75
+ return null;
76
+ }
77
+
78
+ if (p?.type === 'AssignmentExpression') {
79
+ const left = p.left;
80
+
81
+ if (left?.type === 'Identifier') {
82
+ return left.name;
83
+ }
84
+
85
+ if (left?.type === 'MemberExpression' && !left.computed) {
86
+ const object = left.object;
87
+ const property = left.property;
88
+
89
+ const objectName
90
+ = object?.type === 'Identifier'
91
+ ? object.name
92
+ : (object?.type === 'ThisExpression'
93
+ ? 'this'
94
+ : null);
63
95
 
64
- const isMember
65
- = !callee.computed
66
- && property
67
- && property.type === 'Identifier'
68
- && property.name === memberName;
96
+ const propertyName = property?.type === 'Identifier' ? property.name : null;
97
+
98
+ if (objectName && propertyName) {
99
+ return `${objectName}.${propertyName}`;
100
+ }
101
+ }
69
102
 
70
- return isStyleSheet && isMember;
103
+ return null;
104
+ }
105
+
106
+ return null;
71
107
  }
72
108
 
73
109
  function report(node) {
@@ -76,12 +112,16 @@ function create(context) {
76
112
  return;
77
113
  }
78
114
 
115
+ const targetName = getAssignmentTargetName(node);
116
+ const target = targetName ? ` "${targetName}"` : '';
117
+
79
118
  context.report({
80
119
  node,
81
120
  messageId: 'moveStyles',
82
121
  data: {
83
122
  filename,
84
123
  suffixes: allowedSuffixes.join(' or '),
124
+ target,
85
125
  },
86
126
  });
87
127
  }
@@ -100,7 +140,4 @@ function create(context) {
100
140
  };
101
141
  }
102
142
 
103
- module.exports = {
104
- meta,
105
- create,
106
- };
143
+ module.exports = {meta, create};