ilib-lint 2.3.0 → 2.4.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.
@@ -1,6 +1,11 @@
1
1
  Release Notes
2
2
  =============
3
3
 
4
+ ### v2.4.0
5
+
6
+ - added the snake case match rule. If source strings contain only snake case and no whitespace, then the targets must be
7
+ the same. It is treated as Do Not Translate. If the target is different from the source, it is an error.
8
+
4
9
  ### v2.3.0
5
10
 
6
11
  - implemented the XML match rule. If there are XML tags and entities in the
@@ -19,17 +24,20 @@ Release Notes
19
24
  - updated dependencies
20
25
 
21
26
  ### v2.2.0
27
+
22
28
  - added --no-return-value command-line flag to have the linter always return 0, even
23
29
  when there are errors and warnings. This still reports the results to the output.
24
30
  The intention is that the linter can be used to report results without causing
25
31
  build pipelines to fail.
26
32
 
27
33
  ### v2.1.1
34
+
28
35
  - check to make sure that every result in the results array returned by the plugins
29
36
  is not undefined so that we do not run into the problem of dereferencing undefined
30
37
  results later on, which caused some exceptions
31
38
 
32
39
  ### v2.1.0
40
+
33
41
  - fixed a bug where the quote style checker was not converting the highlight quotes properly
34
42
  - added an option `output` to write the output to a file.
35
43
  - added an option `name` to give the project name. It is useful when the config file is shared in multiple projects.
@@ -40,6 +48,7 @@ Release Notes
40
48
  longer accepted.
41
49
 
42
50
  ### v2.0.1
51
+
43
52
  - fixed loading of plugins
44
53
  - if a plugin `ilib-lint-x` exists and a different package `x`
45
54
  also exists that is unrelated to ilib-lint, and the config
@@ -136,7 +145,7 @@ Release Notes
136
145
  substituted into a replacement parameter in the source English text. Nouns
137
146
  and the articles "a", "an", and "the" are not translatable to all languages
138
147
  because of gender and plurality agreement rules.
139
- - converted all unit tests from nodeunit to jest
148
+ - converted all unit tests from nodeunit to jest
140
149
  - updated dependencies
141
150
 
142
151
  ### v1.10.0
@@ -242,7 +251,7 @@ Release Notes
242
251
  - added rule to warn against half-width kana characters
243
252
  - added rule to warn against double-byte whitespace characters
244
253
  - added rule to warn of whitespace adjacent to certain fullwidth punctuation characters
245
- - added rule to warn of a space between double-byte and single-byte character
254
+ - added rule to warn of a space between double-byte and single-byte character
246
255
  - added rule to check whether or not there is a translation for each source string in
247
256
  a resource
248
257
  - removed ability for the ICU plural rule to report results on the
@@ -0,0 +1,68 @@
1
+ # resource-snake-case
2
+
3
+ If the source string contains only snake case and no whitespace, then the target must be the same.
4
+
5
+ The source string is treated as 'Do Not Translate' because snake-cased strings are generally not meant to be translated.
6
+ Instead, they are commonly used in software as identifiers, variable names, or control strings.
7
+
8
+ ## Rule explanation
9
+ Snake case is a way of writing phrases without spaces, where spaces are replaced with underscores (`_`), and the words are typically all lowercase.
10
+
11
+ In this context, any string that conforms to the following rules is considered snake case and should not be translated:
12
+ * Words in mixed case and/or digits separated by underscores (including trailing and leading whitespace), i.e:
13
+ * snake_case,
14
+ * SOME_SCREAMING_SNAKE_CASE,
15
+ * camel_Snake_Case,
16
+ * mixed_CASE,
17
+ * RandomLY_MixED_case,
18
+ * even_MORE_RandomLY_MixED_case_with_numbers123_456,
19
+ * any_case_with_numbers123_456,
20
+ * any_Case_with_Trailing_And_Leading_WHITESPACE ,
21
+
22
+
23
+ * Single word with leading underscore, i.e:
24
+ * _test,
25
+
26
+
27
+ * Digits with leading underscore, i.e:
28
+ * _123,
29
+ * _123_456
30
+
31
+
32
+ * Any case with a leading underscore and/or number, i.e:
33
+ * _test_and_retest,
34
+ * _test_And_REtest,
35
+ * _test_ANd_RETEST,
36
+ * _test_and_RETEST_and123_456,
37
+
38
+
39
+ ## Examples
40
+ ### Correct
41
+ Correctly matched snake case variations in a Spanish (es-ES) translation, where both source and target are the same:
42
+
43
+ 1. snake_case
44
+ - source: `access_granted`
45
+ - target: `access_granted`
46
+
47
+ 2. SCREAMING_SNAKE_CASE
48
+ - source: `ACCESS_GRANTED`
49
+ - target: `ACCESS_GRANTED`
50
+
51
+ 3. camel_Snake_Case
52
+ - source: `access_Granted`
53
+ - target: `access_Granted`
54
+
55
+ 4. mixed_CASE with digits
56
+ - source: `acceSS_GRantEd123_456`
57
+ - target: `acceSS_GRantEd123_456`
58
+
59
+ ### Incorrect
60
+ Incorrectly matched snake case in a Spanish translation:
61
+
62
+ 1. snake_case
63
+ - source: `access_granted`
64
+ - target: `acceso_concedido`
65
+
66
+
67
+ Problems in the above incorrect translation:
68
+ The "access_granted" snake-cased string was translated when it should have been treated as "Do Not Translate".
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ilib-lint",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "module": "./src/index.js",
5
5
  "type": "module",
6
6
  "bin": "./src/index.js",
package/src/Project.js CHANGED
@@ -38,7 +38,8 @@ const rulesetDefinitions = {
38
38
  "resource-quote-style": "localeOnly",
39
39
  "resource-unique-keys": true,
40
40
  "resource-url-match": true,
41
- "resource-named-params": true
41
+ "resource-named-params": true,
42
+ "resource-snake-case": true,
42
43
  }
43
44
  };
44
45
 
@@ -227,7 +227,19 @@ export const regexRules = [
227
227
  ],
228
228
  link: "https://github.com/ilib-js/ilib-lint/blob/main/docs/source-no-manual-date-formatting.md",
229
229
  severity: "error"
230
- }
230
+ },
231
+ {
232
+ type: "resource-matcher",
233
+ name: "resource-snake-case",
234
+ description: "Ensure that when source strings contain only snake case (words and/or numbers separeated by underscores) and no whitespace, then the targets are the same",
235
+ note: "Do not translate the source string if it consists solely of snake-cased strings and/or digits. Please update the target string so it matches the source string.",
236
+ regexps: [
237
+ "^\\s*[a-zA-Z0-9]*(_[a-zA-Z0-9]+)+\\s*$",
238
+ "^\\s*[a-zA-Z0-9]+(_[a-zA-Z0-9]+)*_\\s*$"
239
+ ],
240
+ link: "https://gihub.com/ilib-js/ilib-lint/blob/main/docs/resource-snake-case.md",
241
+ severity: "error"
242
+ },
231
243
  ];
232
244
 
233
245
  // built-in ruleset that contains all the built-in rules
@@ -254,7 +266,8 @@ export const builtInRulesets = {
254
266
  "resource-no-space-between-double-and-single-byte-character": true,
255
267
  "resource-no-halfwidth-kana-characters": true,
256
268
  "resource-no-double-byte-space": true,
257
- "resource-no-space-with-fullwidth-punctuation": true
269
+ "resource-no-space-with-fullwidth-punctuation": true,
270
+ "resource-snake-case": true,
258
271
  },
259
272
 
260
273
  source: {
@@ -145,7 +145,7 @@ class DeclarativeResourceRule extends ResourceRule {
145
145
  let results = [];
146
146
  // only need 1 regexp to match in order to trigger this rule
147
147
  for (const re of this.re) {
148
- results = results.concat(this.checkString({re, source, target, file, resource}));
148
+ results = results.concat(this.checkString({re, source, target, file, resource}) ?? []);
149
149
  if (results.length > 0) break;
150
150
  }
151
151
  results = results.filter(result => result);