eslint-plugin-code-style 1.9.2 → 1.9.3
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 +14 -0
- package/index.js +63 -18
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
+
## [1.9.3] - 2026-02-03
|
|
11
|
+
|
|
12
|
+
### Enhanced
|
|
13
|
+
|
|
14
|
+
- **`no-hardcoded-strings`** - Remove single-word string length limitations and add more special cases:
|
|
15
|
+
- Removed length restrictions (now detects all single-word hardcoded strings)
|
|
16
|
+
- Added validation strings: `empty`, `invalid`, `missing`, `optional`, `required`, `valid`
|
|
17
|
+
- Added auth state strings: `anonymous`, `authenticated`, `authed`, `authorized`, `denied`, `forbidden`, `granted`, `locked`, `loggedin`, `loggedout`, `revoked`, `unauthenticated`, `unauthorized`, `unlocked`, `unverified`, `verified`
|
|
18
|
+
- Added more status strings: `done`, `finished`, `inprogress`, `queued`, `ready`, `running`, `started`, `stopped`, `successful`, `waiting`
|
|
19
|
+
- Made technical patterns stricter to avoid false negatives (camelCase requires uppercase in middle, snake_case requires underscore, kebab-case requires hyphen)
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
10
23
|
## [1.9.2] - 2026-02-03
|
|
11
24
|
|
|
12
25
|
### Enhanced
|
|
@@ -1275,6 +1288,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
1275
1288
|
|
|
1276
1289
|
---
|
|
1277
1290
|
|
|
1291
|
+
[1.9.3]: https://github.com/Mohamed-Elhawary/eslint-plugin-code-style/compare/v1.9.2...v1.9.3
|
|
1278
1292
|
[1.9.2]: https://github.com/Mohamed-Elhawary/eslint-plugin-code-style/compare/v1.9.1...v1.9.2
|
|
1279
1293
|
[1.9.1]: https://github.com/Mohamed-Elhawary/eslint-plugin-code-style/compare/v1.9.0...v1.9.1
|
|
1280
1294
|
[1.9.0]: https://github.com/Mohamed-Elhawary/eslint-plugin-code-style/compare/v1.8.4...v1.9.0
|
package/index.js
CHANGED
|
@@ -14055,20 +14055,21 @@ const noHardcodedStrings = {
|
|
|
14055
14055
|
/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2})?/,
|
|
14056
14056
|
// Time formats
|
|
14057
14057
|
/^\d{1,2}:\d{2}(:\d{2})?(\s?(AM|PM|am|pm))?$/,
|
|
14058
|
-
// JSON keys (
|
|
14059
|
-
|
|
14060
|
-
/^[a-z][a-
|
|
14061
|
-
|
|
14058
|
+
// JSON keys - require actual naming convention markers (underscore/uppercase in middle)
|
|
14059
|
+
// camelCase: must have uppercase letter in middle (e.g., userId, firstName)
|
|
14060
|
+
/^[a-z]+[A-Z][a-zA-Z0-9]*$/,
|
|
14061
|
+
// snake_case: must have underscore (e.g., user_id, first_name)
|
|
14062
|
+
/^[a-z][a-z0-9]*_[a-z0-9_]*$/,
|
|
14063
|
+
// SCREAMING_SNAKE_CASE: must have underscore (e.g., MAX_VALUE, API_URL)
|
|
14064
|
+
/^[A-Z][A-Z0-9]*_[A-Z0-9_]+$/,
|
|
14062
14065
|
// Common technical strings
|
|
14063
14066
|
/^(true|false|null|undefined|NaN|Infinity)$/,
|
|
14064
14067
|
// Content types
|
|
14065
14068
|
/^application\//,
|
|
14066
|
-
// Environment variables pattern
|
|
14067
|
-
/^[A-Z][A-Z0-9_]*$/,
|
|
14068
14069
|
// Query parameters
|
|
14069
14070
|
/^[a-z][a-zA-Z0-9_]*=/,
|
|
14070
|
-
// CSS property-like
|
|
14071
|
-
/^[a-z]+(-[a-z]+)*$/,
|
|
14071
|
+
// CSS property-like (kebab-case): must have hyphen (e.g., font-size, background-color)
|
|
14072
|
+
/^[a-z]+-[a-z]+(-[a-z]+)*$/,
|
|
14072
14073
|
// Numbers with separators
|
|
14073
14074
|
/^[\d,._]+$/,
|
|
14074
14075
|
// Semantic version
|
|
@@ -14164,23 +14165,64 @@ const noHardcodedStrings = {
|
|
|
14164
14165
|
"declined",
|
|
14165
14166
|
"deleted",
|
|
14166
14167
|
"disabled",
|
|
14168
|
+
"done",
|
|
14167
14169
|
"draft",
|
|
14168
14170
|
"enabled",
|
|
14169
14171
|
"expired",
|
|
14170
14172
|
"failed",
|
|
14173
|
+
"finished",
|
|
14171
14174
|
"inactive",
|
|
14175
|
+
"inprogress",
|
|
14172
14176
|
"open",
|
|
14173
14177
|
"paused",
|
|
14174
14178
|
"pending",
|
|
14175
14179
|
"processing",
|
|
14176
14180
|
"published",
|
|
14181
|
+
"queued",
|
|
14182
|
+
"ready",
|
|
14177
14183
|
"rejected",
|
|
14178
14184
|
"resolved",
|
|
14185
|
+
"running",
|
|
14179
14186
|
"scheduled",
|
|
14187
|
+
"started",
|
|
14188
|
+
"stopped",
|
|
14180
14189
|
"submitted",
|
|
14181
14190
|
"success",
|
|
14191
|
+
"successful",
|
|
14182
14192
|
"suspended",
|
|
14183
14193
|
"verified",
|
|
14194
|
+
"waiting",
|
|
14195
|
+
]);
|
|
14196
|
+
|
|
14197
|
+
// Validation/form strings that should be imported from enums/data
|
|
14198
|
+
const validationStrings = new Set([
|
|
14199
|
+
"empty",
|
|
14200
|
+
"invalid",
|
|
14201
|
+
"missing",
|
|
14202
|
+
"optional",
|
|
14203
|
+
"required",
|
|
14204
|
+
"valid",
|
|
14205
|
+
]);
|
|
14206
|
+
|
|
14207
|
+
// Auth/permission state strings that should be imported from enums/data
|
|
14208
|
+
const authStrings = new Set([
|
|
14209
|
+
"anonymous",
|
|
14210
|
+
"authenticated",
|
|
14211
|
+
"authed",
|
|
14212
|
+
"authorized",
|
|
14213
|
+
"denied",
|
|
14214
|
+
"expired",
|
|
14215
|
+
"forbidden",
|
|
14216
|
+
"granted",
|
|
14217
|
+
"locked",
|
|
14218
|
+
"loggedin",
|
|
14219
|
+
"loggedout",
|
|
14220
|
+
"revoked",
|
|
14221
|
+
"unauthenticated",
|
|
14222
|
+
"unauthorized",
|
|
14223
|
+
"unlocked",
|
|
14224
|
+
"unverified",
|
|
14225
|
+
"verified",
|
|
14184
14226
|
]);
|
|
14185
14227
|
|
|
14186
14228
|
// Priority levels that should be imported from enums/data
|
|
@@ -14203,6 +14245,8 @@ const noHardcodedStrings = {
|
|
|
14203
14245
|
const isLogLevelHandler = (str) => logLevels.has(str.toLowerCase());
|
|
14204
14246
|
const isStatusStringHandler = (str) => statusStrings.has(str.toLowerCase());
|
|
14205
14247
|
const isPriorityLevelHandler = (str) => priorityLevels.has(str.toLowerCase());
|
|
14248
|
+
const isValidationStringHandler = (str) => validationStrings.has(str.toLowerCase());
|
|
14249
|
+
const isAuthStringHandler = (str) => authStrings.has(str.toLowerCase());
|
|
14206
14250
|
|
|
14207
14251
|
// Check if string should be flagged even if it matches technical patterns
|
|
14208
14252
|
const isFlaggedSpecialStringHandler = (str) => isHttpStatusCodeHandler(str)
|
|
@@ -14211,7 +14255,9 @@ const noHardcodedStrings = {
|
|
|
14211
14255
|
|| isEnvironmentNameHandler(str)
|
|
14212
14256
|
|| isLogLevelHandler(str)
|
|
14213
14257
|
|| isStatusStringHandler(str)
|
|
14214
|
-
|| isPriorityLevelHandler(str)
|
|
14258
|
+
|| isPriorityLevelHandler(str)
|
|
14259
|
+
|| isValidationStringHandler(str)
|
|
14260
|
+
|| isAuthStringHandler(str);
|
|
14215
14261
|
|
|
14216
14262
|
// Get descriptive error message based on string type
|
|
14217
14263
|
const getErrorMessageHandler = (str, context = "") => {
|
|
@@ -14246,6 +14292,14 @@ const noHardcodedStrings = {
|
|
|
14246
14292
|
return `Hardcoded priority level "${truncatedStr}"${contextPart} should be imported from @/enums or @/data`;
|
|
14247
14293
|
}
|
|
14248
14294
|
|
|
14295
|
+
if (isValidationStringHandler(str)) {
|
|
14296
|
+
return `Hardcoded validation string "${truncatedStr}"${contextPart} should be imported from @/enums or @/data`;
|
|
14297
|
+
}
|
|
14298
|
+
|
|
14299
|
+
if (isAuthStringHandler(str)) {
|
|
14300
|
+
return `Hardcoded auth state "${truncatedStr}"${contextPart} should be imported from @/enums or @/data`;
|
|
14301
|
+
}
|
|
14302
|
+
|
|
14249
14303
|
return `Hardcoded string "${truncatedStr}"${contextPart} should be imported from @/data or @/strings or @/constants or @/@constants or @/@strings`;
|
|
14250
14304
|
};
|
|
14251
14305
|
|
|
@@ -14499,9 +14553,6 @@ const noHardcodedStrings = {
|
|
|
14499
14553
|
// Check if it looks like user-facing text - skip for special strings
|
|
14500
14554
|
if (!isSpecialString && !/[a-zA-Z]/.test(str)) return;
|
|
14501
14555
|
|
|
14502
|
-
// Require multiple words or reasonable length for non-special strings
|
|
14503
|
-
if (!isSpecialString && str.split(/\s+/).length < 2 && str.length < 10) return;
|
|
14504
|
-
|
|
14505
14556
|
context.report({
|
|
14506
14557
|
message: getErrorMessageHandler(str, `attribute "${attrName}"`),
|
|
14507
14558
|
node: node.value,
|
|
@@ -14525,9 +14576,6 @@ const noHardcodedStrings = {
|
|
|
14525
14576
|
|
|
14526
14577
|
if (!isSpecialString && !/[a-zA-Z]/.test(str)) return;
|
|
14527
14578
|
|
|
14528
|
-
// Require multiple words or reasonable length for non-special strings
|
|
14529
|
-
if (!isSpecialString && str.split(/\s+/).length < 2 && str.length < 10) return;
|
|
14530
|
-
|
|
14531
14579
|
context.report({
|
|
14532
14580
|
message: getErrorMessageHandler(str, `attribute "${attrName}"`),
|
|
14533
14581
|
node: expression,
|
|
@@ -14567,9 +14615,6 @@ const noHardcodedStrings = {
|
|
|
14567
14615
|
// Skip if it doesn't look like user-facing text - but not for special strings
|
|
14568
14616
|
if (!isSpecialString && !/[a-zA-Z]/.test(str)) return;
|
|
14569
14617
|
|
|
14570
|
-
// Require at least 2 words or be reasonably long - but not for special strings
|
|
14571
|
-
if (!isSpecialString && str.split(/\s+/).length < 2 && str.length < 15) return;
|
|
14572
|
-
|
|
14573
14618
|
context.report({
|
|
14574
14619
|
message: getErrorMessageHandler(str),
|
|
14575
14620
|
node,
|
package/package.json
CHANGED