ilib-lint 2.7.0 → 2.7.2
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/README.md +18 -18
- package/package.json +12 -12
- package/src/config/README.md +1 -1
- package/src/formatters/ConfigBasedFormatter.js +6 -5
- package/src/formatters/__tests__/ConfigBasedFormatter.test.js +61 -0
- package/src/plugins/BuiltinPlugin.js +17 -17
- package/src/rules/DeclarativeResourceRule.js +8 -3
- package/src/rules/ResourceCamelCase.js +1 -1
- package/src/rules/ResourceCompleteness.js +5 -2
- package/src/rules/ResourceDNTTerms.js +10 -6
- package/src/rules/ResourceEdgeWhitespace.js +1 -1
- package/src/rules/ResourceICUPluralTranslation.js +1 -1
- package/src/rules/ResourceICUPlurals.js +1 -1
- package/src/rules/ResourceNoTranslation.js +1 -1
- package/src/rules/ResourceQuoteStyle.js +8 -4
- package/src/rules/ResourceSnakeCase.js +1 -1
- package/src/rules/ResourceSourceICUPluralCategories.js +1 -1
- package/src/rules/ResourceSourceICUPluralParams.js +1 -1
- package/src/rules/ResourceSourceICUPluralSyntax.js +1 -1
- package/src/rules/ResourceSourceICUUnexplainedParams.js +3 -3
- package/src/rules/ResourceStateChecker.js +1 -1
- package/src/rules/ResourceUniqueKeys.js +2 -2
- package/src/rules/ResourceXML.js +2 -2
- package/src/rules/utils.js +4 -1
package/README.md
CHANGED
|
@@ -219,7 +219,7 @@ or any of them at the same time.
|
|
|
219
219
|
## Common Code
|
|
220
220
|
|
|
221
221
|
All plugins should import and use the classes in the
|
|
222
|
-
[ilib-lint-common](https://github.com/
|
|
222
|
+
[ilib-lint-common](https://github.com/iLib-js/ilib-mono/tree/main/packages/ilib-lint-common) package.
|
|
223
223
|
This defines the super classes for each plugin type, as well as a number
|
|
224
224
|
of utility classes and functions.
|
|
225
225
|
|
|
@@ -259,7 +259,7 @@ representation so that the appropriate rules can parse that representation.
|
|
|
259
259
|
The standard representations are:
|
|
260
260
|
|
|
261
261
|
- resources - the file is converted into an array of
|
|
262
|
-
[Resource](https://github.com/iLib-js/ilib-
|
|
262
|
+
[Resource](https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-tools-common/src/Resource.js)
|
|
263
263
|
instances
|
|
264
264
|
- lines - the file in converted into a simple array of lines
|
|
265
265
|
- source - the file is not parsed. Instead, the entire text of the file is used to
|
|
@@ -269,7 +269,7 @@ The resources representation is intended to represent entries in resource files
|
|
|
269
269
|
such as xliff files, gnu po files, or java properties files. Each entry in the
|
|
270
270
|
resource file is represented as an instance of one of the standard resource
|
|
271
271
|
classes all defined in the
|
|
272
|
-
[ilib-tools-common](https://github.com/
|
|
272
|
+
[ilib-tools-common](https://github.com/iLib-js/ilib-mono/tree/main/packages/ilib-tools-common/src)
|
|
273
273
|
project:
|
|
274
274
|
|
|
275
275
|
- ResourceString - the resource is a single string
|
|
@@ -288,13 +288,13 @@ for your class should define the following properties:
|
|
|
288
288
|
- `this.description` - a description of this type of parser to display to users
|
|
289
289
|
|
|
290
290
|
It should also override the
|
|
291
|
-
[parseData()](https://github.com/iLib-js/ilib-
|
|
291
|
+
[parseData()](https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint-common/src/Parser.js)
|
|
292
292
|
method which parses a string, and the
|
|
293
|
-
[parse()](https://github.com/iLib-js/ilib-
|
|
293
|
+
[parse()](https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint-common/src/Parser.js)
|
|
294
294
|
method, which loads data from the file and then parses it.
|
|
295
295
|
|
|
296
296
|
You can see an example of a parser plugin by looking at the gnu PO file parser at
|
|
297
|
-
[ilib-lint-python-gnu](https://github.com/
|
|
297
|
+
[ilib-lint-python-gnu](https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint-python-gnu/src/POParser.js).
|
|
298
298
|
That parser interprets a .po file as a resource file and returns a set of
|
|
299
299
|
Resource instances.
|
|
300
300
|
|
|
@@ -302,7 +302,7 @@ Resource instances.
|
|
|
302
302
|
|
|
303
303
|
Rules interpret the intermediate representation of a file produced by a Parser
|
|
304
304
|
and produce a single
|
|
305
|
-
[Result](https://github.com/iLib-js/ilib-
|
|
305
|
+
[Result](https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint-common/src/Result.js)
|
|
306
306
|
instance, an array of Result instances, one for each problem found, or undefined
|
|
307
307
|
if there are no problems found.
|
|
308
308
|
|
|
@@ -370,8 +370,8 @@ locale first needs to look up what the correct quote style even is in
|
|
|
370
370
|
order to apply the rule.
|
|
371
371
|
|
|
372
372
|
In order to create a rule instance, create a class that extends the
|
|
373
|
-
[Rule](https://github.com/
|
|
374
|
-
class in the [ilib-lint-common](https://github.com/
|
|
373
|
+
[Rule](https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint-common/src/Rule.js)
|
|
374
|
+
class in the [ilib-lint-common](https://github.com/iLib-js/ilib-mono/tree/main/packages/ilib-lint-common) package.
|
|
375
375
|
The constructor of this class should define the following properties:
|
|
376
376
|
|
|
377
377
|
- `this.name` - a unique name for this rule
|
|
@@ -389,13 +389,13 @@ part is that the name should uniquely identify your Rule so that you can use it
|
|
|
389
389
|
in config files.
|
|
390
390
|
|
|
391
391
|
The rule should also override and implement the getRuleType() method and the
|
|
392
|
-
[match()](https://github.com/iLib-js/ilib-
|
|
392
|
+
[match()](https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint-common/src/Rule.js) method,
|
|
393
393
|
which takes an intermediate representation as a parameter and returns either
|
|
394
394
|
a single Result, an array of Result, or undefined.
|
|
395
395
|
|
|
396
396
|
If you would like to see an example rule plugin, see the definition of
|
|
397
397
|
the built-in ICU plural matcher rule:
|
|
398
|
-
[resource-icu-plurals](https://github.com/
|
|
398
|
+
[resource-icu-plurals](https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/src/rules/ResourceICUPlurals.js)
|
|
399
399
|
which checks resources to make sure that plurals in source and target strings
|
|
400
400
|
have the correct syntax for ICU and formatjs.
|
|
401
401
|
|
|
@@ -435,7 +435,7 @@ syntax. (Each rule defines for itself what parameters/initalizers it accepts.)
|
|
|
435
435
|
|
|
436
436
|
### Formatters
|
|
437
437
|
|
|
438
|
-
Formatters transform a [Result object](https://github.com/iLib-js/ilib-
|
|
438
|
+
Formatters transform a [Result object](https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint-common/src/Result.js) into a format that the consumer can use. For the most part, the consumer
|
|
439
439
|
is a human, so the result should be formatted in text so that the user can read
|
|
440
440
|
it easily. Other times, the consumer is another program, so the result should be
|
|
441
441
|
formatted for easy parsing. Formatters can formats the results in any way necessary.
|
|
@@ -468,8 +468,8 @@ sure that fields in a CSV file are escaped properly to conform to CSV syntax, an
|
|
|
468
468
|
include escaping code in it.
|
|
469
469
|
|
|
470
470
|
In order to create a formatter instance, create a class that extends the
|
|
471
|
-
[Formatter](https://github.com/
|
|
472
|
-
class in the [ilib-lint-common](https://github.com/
|
|
471
|
+
[Formatter](https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint-common/src/Formatter.js)
|
|
472
|
+
class in the [ilib-lint-common](https://github.com/iLib-js/ilib-mono/tree/main/packages/ilib-lint-common) project.
|
|
473
473
|
The constructor of this class should define the following properties:
|
|
474
474
|
|
|
475
475
|
- `this.name` - a unique name for this formatter
|
|
@@ -478,17 +478,17 @@ The constructor of this class should define the following properties:
|
|
|
478
478
|
of the rule and how to resolve the problem it found
|
|
479
479
|
|
|
480
480
|
The formatter should also override and implement the
|
|
481
|
-
[format()](https://github.com/iLib-js/ilib-
|
|
481
|
+
[format()](https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint-common/src/Formatter.js) method,
|
|
482
482
|
which takes a Result instance as a parameter and returns a formatted string.
|
|
483
483
|
|
|
484
484
|
If you would like to look at an example formatter plugin, see the definition of
|
|
485
485
|
the built-in default formatter
|
|
486
|
-
[ansi-console-formatter](https://github.com/
|
|
486
|
+
[ansi-console-formatter](https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/src/formatters/AnsiConsoleFormatter.js)
|
|
487
487
|
which formats a Result for colorful output on an ANSI console.
|
|
488
488
|
|
|
489
489
|
## Example Plugin
|
|
490
490
|
|
|
491
|
-
You can take a look at the [ilib-lint-python](https://github.com/
|
|
491
|
+
You can take a look at the [ilib-lint-python](https://github.com/iLib-js/ilib-mono/tree/main/packages/ilib-lint-python)
|
|
492
492
|
plugin as a working example of ilib-lint plugin. It implements some rules that
|
|
493
493
|
check the various types of substitution parameters that python/django and
|
|
494
494
|
gnu gettext support.
|
|
@@ -583,4 +583,4 @@ distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
583
583
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
584
584
|
|
|
585
585
|
See the License for the specific language governing permissions and
|
|
586
|
-
limitations under the License.
|
|
586
|
+
limitations under the License.
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ilib-lint",
|
|
3
|
-
"version": "2.7.
|
|
4
|
-
"module": "./src/index.js",
|
|
3
|
+
"version": "2.7.2",
|
|
5
4
|
"type": "module",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"module": "./src/index.js",
|
|
6
7
|
"bin": "./src/index.js",
|
|
7
8
|
"description": "A linter for i18n issues for any type of project",
|
|
8
9
|
"keywords": [
|
|
@@ -15,7 +16,7 @@
|
|
|
15
16
|
"lint",
|
|
16
17
|
"locale"
|
|
17
18
|
],
|
|
18
|
-
"homepage": "https://github.com/iLib-js/ilib-mono/packages/ilib-lint",
|
|
19
|
+
"homepage": "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint",
|
|
19
20
|
"bugs": "https://github.com/iLib-js/ilib-mono/issues",
|
|
20
21
|
"email": "marketing@translationcircle.com",
|
|
21
22
|
"license": "Apache-2.0",
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
],
|
|
43
44
|
"repository": {
|
|
44
45
|
"type": "git",
|
|
45
|
-
"url": "https://github.com/iLib-js/ilib-
|
|
46
|
+
"url": "https://github.com/iLib-js/ilib-mono.git"
|
|
46
47
|
},
|
|
47
48
|
"engines": {
|
|
48
49
|
"node": ">=14.0.0"
|
|
@@ -61,27 +62,26 @@
|
|
|
61
62
|
},
|
|
62
63
|
"dependencies": {
|
|
63
64
|
"@formatjs/intl": "^2.10.4",
|
|
64
|
-
"ilib-common": "^1.1.3",
|
|
65
|
-
"ilib-lint-common": "^3.1.0",
|
|
66
65
|
"ilib-locale": "^1.2.2",
|
|
67
66
|
"ilib-localeinfo": "^1.1.0",
|
|
68
|
-
"ilib-tools-common": "^1.11.0",
|
|
69
67
|
"intl-messageformat": "^10.5",
|
|
70
68
|
"json5": "^2.2.3",
|
|
71
69
|
"log4js": "^6.9.1",
|
|
72
70
|
"micromatch": "^4.0.7",
|
|
73
71
|
"options-parser": "^0.4.0",
|
|
74
|
-
"xml-js": "^1.6.11"
|
|
72
|
+
"xml-js": "^1.6.11",
|
|
73
|
+
"ilib-common": "^1.1.6",
|
|
74
|
+
"ilib-tools-common": "^1.12.2",
|
|
75
|
+
"ilib-lint-common": "^3.1.2"
|
|
75
76
|
},
|
|
76
77
|
"scripts": {
|
|
77
|
-
"dist": "pnpm pack",
|
|
78
78
|
"test": "pnpm test:jest",
|
|
79
|
-
"test:jest": "LANG=en_US.UTF8
|
|
79
|
+
"test:jest": "LANG=en_US.UTF8 node --trace-warnings --experimental-vm-modules node_modules/jest/bin/jest.js",
|
|
80
80
|
"test:watch": "pnpm test:jest --watch",
|
|
81
|
-
"debug": "LANG=en_US.UTF8
|
|
81
|
+
"debug": "LANG=en_US.UTF8 node --experimental-vm-modules --inspect-brk node_modules/jest/bin/jest.js -i",
|
|
82
82
|
"lint": "node src/index.js",
|
|
83
83
|
"clean": "git clean -f -d src test",
|
|
84
|
-
"doc": "mkdir -p docs
|
|
84
|
+
"doc": "mkdir -p docs && jsdoc2md -c jsdoc.json --separators --source src/* -m table > docs/ilibLint.md && pnpm doc:html",
|
|
85
85
|
"doc:html": "jsdoc -c jsdoc.json",
|
|
86
86
|
"types": "tsc -p ./jsconfig.json"
|
|
87
87
|
}
|
package/src/config/README.md
CHANGED
|
@@ -134,7 +134,7 @@ Here is an example of a configuration file:
|
|
|
134
134
|
"description": "Ensure that named parameters that appear in the source string are also used in the translated string",
|
|
135
135
|
"note": "The named parameter '{matchString}' from the source string does not appear in the target string",
|
|
136
136
|
"regexps": ["\\{\\w+\\}"],
|
|
137
|
-
"link": "https://github.com/
|
|
137
|
+
"link": "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/README.md"
|
|
138
138
|
}
|
|
139
139
|
],
|
|
140
140
|
"formatters": [
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import log4js from 'log4js';
|
|
20
20
|
|
|
21
|
-
import {
|
|
21
|
+
import {Formatter, Result} from 'ilib-lint-common';
|
|
22
22
|
|
|
23
23
|
var logger = log4js.getLogger("ilib-lint.formatters.ConfigBasedFormatter");
|
|
24
24
|
|
|
@@ -50,13 +50,13 @@ export class ConfigBasedFormatter extends Formatter {
|
|
|
50
50
|
*/
|
|
51
51
|
constructor(options) {
|
|
52
52
|
super(options);
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
if (!options) {
|
|
55
55
|
throw "Attempt to create a ConfigBasedFormatter without options";
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
for (let prop of requiredFields) {
|
|
59
|
-
if (typeof(options[prop]) === 'undefined') {
|
|
59
|
+
if (typeof (options[prop]) === 'undefined') {
|
|
60
60
|
throw `Missing ${prop} field for a ConfigBasedFormatter`;
|
|
61
61
|
}
|
|
62
62
|
this[prop] = options[prop];
|
|
@@ -73,7 +73,7 @@ export class ConfigBasedFormatter extends Formatter {
|
|
|
73
73
|
format(result) {
|
|
74
74
|
if (!result) return "";
|
|
75
75
|
let output = this.template;
|
|
76
|
-
|
|
76
|
+
|
|
77
77
|
for (let prop of resultFields) {
|
|
78
78
|
output = output.replace(new RegExp(`{${prop}}`, "g"), result[prop] || "");
|
|
79
79
|
}
|
|
@@ -82,11 +82,12 @@ export class ConfigBasedFormatter extends Formatter {
|
|
|
82
82
|
output = output.replace(new RegExp("{ruleDescription}", "g"), result.rule.getDescription());
|
|
83
83
|
|
|
84
84
|
output = output.replace(/<e\d><\/e\d>/g, `${this.highlightStart}${this.highlightEnd}`);
|
|
85
|
+
output = output.replace(/<e\d\/>/g, `${this.highlightStart}${this.highlightEnd}`);
|
|
85
86
|
output = output.replace(/<e\d>/g, this.highlightStart);
|
|
86
87
|
output = output.replace(/<\/e\d>/g, this.highlightEnd);
|
|
87
88
|
|
|
88
89
|
let link = "";
|
|
89
|
-
if (typeof(result.rule.getLink) === 'function') {
|
|
90
|
+
if (typeof (result.rule.getLink) === 'function') {
|
|
90
91
|
link = result.rule.getLink() || "";
|
|
91
92
|
}
|
|
92
93
|
output = output.replace(new RegExp("{ruleLink}", "g"), link);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {Result} from 'ilib-lint-common';
|
|
2
|
+
import {ConfigBasedFormatter} from '../ConfigBasedFormatter.js';
|
|
3
|
+
import ResourceMatcher from "../../rules/ResourceMatcher.js";
|
|
4
|
+
|
|
5
|
+
describe('ConfigBasedFormatter', () => {
|
|
6
|
+
it.each([
|
|
7
|
+
{
|
|
8
|
+
name: "a pair of opening and closing tags <eX></eX>",
|
|
9
|
+
highlight: "This is just <e0>me</e0> testing.",
|
|
10
|
+
expected: "This is just >>me<< testing."
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: "a self-closing tag <eX/>",
|
|
14
|
+
highlight: "This is just me testing.<e0/>",
|
|
15
|
+
expected: "This is just me testing.>><<"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: "an opening tag <eX>",
|
|
19
|
+
highlight: "This is just me testing.<e0>",
|
|
20
|
+
expected: "This is just me testing.>>"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: "a closing tag </eX>",
|
|
24
|
+
highlight: "This is just me testing.</e0>",
|
|
25
|
+
expected: "This is just me testing.<<"
|
|
26
|
+
},
|
|
27
|
+
])('replaces $name with highlight markers', ({highlight, expected}) => {
|
|
28
|
+
const formatter = new ConfigBasedFormatter({
|
|
29
|
+
"name": "test-formatter",
|
|
30
|
+
"description": "A formatter for testing purposes",
|
|
31
|
+
"template": "{highlight}",
|
|
32
|
+
"highlightStart": ">>",
|
|
33
|
+
"highlightEnd": "<<"
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const result = formatter.format(new Result({
|
|
37
|
+
description: "A description for testing purposes",
|
|
38
|
+
highlight,
|
|
39
|
+
id: "test.id",
|
|
40
|
+
lineNumber: 123,
|
|
41
|
+
pathName: "test.txt",
|
|
42
|
+
rule: getTestRule(),
|
|
43
|
+
severity: "error",
|
|
44
|
+
source: "test"
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
expect(result).toBe(expected);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
function getTestRule() {
|
|
53
|
+
return new ResourceMatcher({
|
|
54
|
+
"name": "testRule",
|
|
55
|
+
"description": "Rule for testing purposes",
|
|
56
|
+
"regexps": ["test"],
|
|
57
|
+
"note": "test",
|
|
58
|
+
"sourceLocale": "en-US",
|
|
59
|
+
"link": ""
|
|
60
|
+
});
|
|
61
|
+
}
|
|
@@ -51,7 +51,7 @@ export const regexRules = [
|
|
|
51
51
|
description: "Ensure that URLs that appear in the source string are also used in the translated string",
|
|
52
52
|
note: "URL '{matchString}' from the source string does not appear in the target string",
|
|
53
53
|
regexps: [ "((https?|github|ftps?|mailto|file|data|irc):\\/\\/)([\\da-zA-Z\\.-]+)\\.([a-zA-Z\\.]{2,6})([\\/\w\\.-]*)*\\/?" ],
|
|
54
|
-
link: "https://github.com/
|
|
54
|
+
link: "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-url-match.md"
|
|
55
55
|
},
|
|
56
56
|
{
|
|
57
57
|
type: "resource-matcher",
|
|
@@ -59,7 +59,7 @@ export const regexRules = [
|
|
|
59
59
|
description: "Ensure that named parameters that appear in the source string are also used in the translated string",
|
|
60
60
|
note: "The named parameter '{matchString}' from the source string does not appear in the target string",
|
|
61
61
|
regexps: [ "\\{\\w+\\}" ],
|
|
62
|
-
link: "https://github.com/
|
|
62
|
+
link: "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-named-params.md"
|
|
63
63
|
},
|
|
64
64
|
{
|
|
65
65
|
type: "resource-target",
|
|
@@ -67,7 +67,7 @@ export const regexRules = [
|
|
|
67
67
|
description: "Ensure that the target does not contain any full-width Latin characters.",
|
|
68
68
|
note: "The full-width characters '{matchString}' are not allowed in the target string. Use ASCII letters instead.",
|
|
69
69
|
regexps: [ "[\\uFF21-\\uFF3A\\uFF41-\\uFF5A]+" ],
|
|
70
|
-
link: "https://github.com/
|
|
70
|
+
link: "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-no-fullwidth-latin.md"
|
|
71
71
|
},
|
|
72
72
|
{
|
|
73
73
|
type: "resource-target",
|
|
@@ -75,7 +75,7 @@ export const regexRules = [
|
|
|
75
75
|
description: "Ensure that the target does not contain any full-width digits.",
|
|
76
76
|
note: "The full-width characters '{matchString}' are not allowed in the target string. Use ASCII digits instead.",
|
|
77
77
|
regexps: [ "[\\uFF10-\\uFF19]+" ],
|
|
78
|
-
link: "https://github.com/
|
|
78
|
+
link: "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-no-fullwidth-digits.md"
|
|
79
79
|
},
|
|
80
80
|
{
|
|
81
81
|
type: "resource-target",
|
|
@@ -83,7 +83,7 @@ export const regexRules = [
|
|
|
83
83
|
description: "Ensure that the target does not contain specific full-width punctuation: percent sign, question mark, or exclamation mark.",
|
|
84
84
|
note: "The full-width characters '{matchString}' are not allowed in the target string. Use ASCII symbols instead.",
|
|
85
85
|
regexps: [ "[\\uFF01\\uFF05\\uFF1F]+" ],
|
|
86
|
-
link: "https://github.com/
|
|
86
|
+
link: "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-no-fullwidth-punctuation-subset.md",
|
|
87
87
|
locales: "ja"
|
|
88
88
|
},
|
|
89
89
|
{
|
|
@@ -92,7 +92,7 @@ export const regexRules = [
|
|
|
92
92
|
description: "Ensure that the target does not contain a space character between a double-byte and single-byte character.",
|
|
93
93
|
note: "The space character is not allowed in the target string between a double- and single-byte character. Remove the space character.",
|
|
94
94
|
regexps: [ "[\\u3040-\\u309F\\u30A0-\\u30FF\\u4E00-\\u9FAF]\\s+[\\x00-\\x20\\x30-\\x39\\x41-\\x5A\\x61-\\x7A\\x8A\\x8C\\x8E\\x9A\\x9C\\x9E\\x9F\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\xFF]|[\\x00-\\x20\\x30-\\x39\\x41-\\x5A\\x61-\\x7A\\x8A\\x8C\\x8E\\x9A\\x9C\\x9E\\x9F\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\xFF]\\s+[\\u3040-\\u309F\\u30A0-\\u30FF\\u4E00-\\u9FAF]" ],
|
|
95
|
-
link: "https://github.com/
|
|
95
|
+
link: "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-no-space-between-double-and-single-byte-character.md",
|
|
96
96
|
severity: "warning",
|
|
97
97
|
locales: "ja"
|
|
98
98
|
},
|
|
@@ -102,7 +102,7 @@ export const regexRules = [
|
|
|
102
102
|
description: "Ensure that the target does not contain half-width kana characters.",
|
|
103
103
|
note: "The half-width kana characters are not allowed in the target string. Use full-width characters.",
|
|
104
104
|
regexps: [ "[ァ-ン゙゚]+" ],
|
|
105
|
-
link: "https://github.com/
|
|
105
|
+
link: "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-no-halfwidth-kana-characters.md",
|
|
106
106
|
severity: "warning"
|
|
107
107
|
},
|
|
108
108
|
{
|
|
@@ -112,7 +112,7 @@ export const regexRules = [
|
|
|
112
112
|
note: "Double-byte space characters should not be used in the target string. Use ASCII symbols instead.",
|
|
113
113
|
// per https://en.wikipedia.org/wiki/Whitespace_character
|
|
114
114
|
regexps: [ "[\\u1680\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200A\\u2028\\u2029\\u202F\\u205F\\u3000]+" ],
|
|
115
|
-
link: "https://github.com/
|
|
115
|
+
link: "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-no-double-byte-space.md",
|
|
116
116
|
severity: "warning",
|
|
117
117
|
locales: "ja"
|
|
118
118
|
},
|
|
@@ -122,7 +122,7 @@ export const regexRules = [
|
|
|
122
122
|
description: "Ensure that there is no whitespace adjacent to the fullwidth punctuation characters.",
|
|
123
123
|
note: "There should be no space adjacent to fullwidth punctuation characters '{matchString}'. Remove it.",
|
|
124
124
|
regexps: [ "(\\s+[\\u3001\\u3002\\u3008-\\u3011\\u3014-\\u301B]|[\\u3001\\u3002\\u3008-\\u3011\\u3014-\\u301B]\\s+)" ],
|
|
125
|
-
link: "https://github.com/
|
|
125
|
+
link: "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-no-space-with-fullwidth-punctuation.md",
|
|
126
126
|
severity: "warning",
|
|
127
127
|
locales: "ja"
|
|
128
128
|
},
|
|
@@ -132,7 +132,7 @@ export const regexRules = [
|
|
|
132
132
|
description: "Ensure that there are no replacement variables surrounded by single quotes which escape them in the source strings.",
|
|
133
133
|
note: "There should be no escaped replacement parameters. Use Unicode quotes ‘like this’ (U+2018 and U+2019) or double quotes instead.",
|
|
134
134
|
regexps: [ "(?:^|[^'])(?<match>''?\\{.*?\\}''?)" ],
|
|
135
|
-
link: "https://github.com/
|
|
135
|
+
link: "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/source-no-escaped-curly-braces.md",
|
|
136
136
|
severity: "error",
|
|
137
137
|
useStripped: false
|
|
138
138
|
},
|
|
@@ -142,7 +142,7 @@ export const regexRules = [
|
|
|
142
142
|
description: "Ensure that there are no replacement variables surrounded by single quotes which escape them in the target strings.",
|
|
143
143
|
note: "There should be no escaped replacement parameters in the translation. Use quotes that are native for the target language or use tripled single-quotes instead.",
|
|
144
144
|
regexps: [ "(?:^|[^'])(?<match>''?\\{.*?\\}''?)" ],
|
|
145
|
-
link: "https://github.com/
|
|
145
|
+
link: "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-no-escaped-curly-braces.md",
|
|
146
146
|
severity: "error",
|
|
147
147
|
useStripped: false
|
|
148
148
|
},
|
|
@@ -152,7 +152,7 @@ export const regexRules = [
|
|
|
152
152
|
description: "Ensure that source strings do not contain dashes in the replacement parameters.",
|
|
153
153
|
note: "Dashes are not allowed in replacement parameters. Use a different character such as underscore.",
|
|
154
154
|
regexps: [ "(?:^|[^'])(?<match>\\{[^}]*?-[^}]*\\})" ],
|
|
155
|
-
link: "https://github.com/
|
|
155
|
+
link: "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/source-no-dashes-in-replacement-params.md",
|
|
156
156
|
severity: "error"
|
|
157
157
|
},
|
|
158
158
|
{
|
|
@@ -161,7 +161,7 @@ export const regexRules = [
|
|
|
161
161
|
description: "Ensure that source strings do not contain the (s) construct to indicate a possible plural. That is not translatable to many languages.",
|
|
162
162
|
note: "The (s) construct is not allowed in source strings. Use real plural syntax instead.",
|
|
163
163
|
regexps: [ "(?<match>\\w+\\(s\\))(?:\\s|\\p{P}|$)" ], // \p{P} means punctuation
|
|
164
|
-
link: "https://github.com/
|
|
164
|
+
link: "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/source-no-lazy-plurals.md",
|
|
165
165
|
severity: "warning"
|
|
166
166
|
},
|
|
167
167
|
{
|
|
@@ -170,7 +170,7 @@ export const regexRules = [
|
|
|
170
170
|
description: "Ensure that source strings do not contain percentage formatting. Percentages should be formatted using a locale-sensitive number formatter instead.",
|
|
171
171
|
note: "Do not format percentages in English strings. Use a locale-sensitive number formatter and substitute the result of that into this string.",
|
|
172
172
|
regexps: [ "(?<match>\\{[\\w_.$0-9]+\\}\\s*%)(\\s|$)" ],
|
|
173
|
-
link: "https://github.com/
|
|
173
|
+
link: "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/source-no-manual-percentage-formatting.md",
|
|
174
174
|
severity: "warning"
|
|
175
175
|
},
|
|
176
176
|
{
|
|
@@ -179,7 +179,7 @@ export const regexRules = [
|
|
|
179
179
|
description: "Ensure that source strings do not contain replacement parameters that are nouns or adjectives.",
|
|
180
180
|
note: "Do not substitute nouns into UI strings. Use separate strings for each noun instead.",
|
|
181
181
|
regexps: [ "\\b(?<match>([Aa][Nn]?|[Tt][Hh][Ee])\\s+\\{.*?\\})" ],
|
|
182
|
-
link: "https://github.com/
|
|
182
|
+
link: "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/source-no-noun-replacement-params.md",
|
|
183
183
|
severity: "error",
|
|
184
184
|
useStripped: false
|
|
185
185
|
},
|
|
@@ -189,7 +189,7 @@ export const regexRules = [
|
|
|
189
189
|
description: "Ensure that source strings do not contain currency formatting. Currencies should be formatted using a locale-sensitive number formatter instead.",
|
|
190
190
|
note: "Do not format currencies in English strings. Use a locale-sensitive number formatter and substitute the result of that into this string.",
|
|
191
191
|
regexps: [ "(?<match>\\$\\s*\\{[\\w_.$0-9]+\\})" ],
|
|
192
|
-
link: "https://github.com/
|
|
192
|
+
link: "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/source-no-manual-currency-formatting.md",
|
|
193
193
|
severity: "error"
|
|
194
194
|
},
|
|
195
195
|
{
|
|
@@ -230,7 +230,7 @@ export const regexRules = [
|
|
|
230
230
|
"\\{[Hh][Hh]?\\}:\\{[Mm][Mm]?\\}:\\{[Ss][Ss]?\\}",
|
|
231
231
|
"\\{[Hh][Hh]?\\}:\\{[Mm][Mm]?\\}"
|
|
232
232
|
],
|
|
233
|
-
link: "https://github.com/
|
|
233
|
+
link: "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/source-no-manual-date-formatting.md",
|
|
234
234
|
severity: "error"
|
|
235
235
|
},
|
|
236
236
|
];
|
|
@@ -19,9 +19,12 @@
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
import Locale from 'ilib-locale';
|
|
22
|
-
|
|
23
22
|
import ResourceRule from './ResourceRule.js';
|
|
24
23
|
|
|
24
|
+
// type imports
|
|
25
|
+
/** @ignore @typedef {import("ilib-tools-common").Resource} Resource */
|
|
26
|
+
/** @ignore @typedef {import("ilib-lint-common").Result} Result */
|
|
27
|
+
|
|
25
28
|
// figure out which regex flags are supported on this version of node
|
|
26
29
|
let regexFlags = "g";
|
|
27
30
|
|
|
@@ -43,6 +46,8 @@ function getLangSpec(spec) {
|
|
|
43
46
|
return locale.getLangSpec();
|
|
44
47
|
}
|
|
45
48
|
|
|
49
|
+
/** @ignore @typedef {("error"|"warning"|"suggestion")} Severity */
|
|
50
|
+
|
|
46
51
|
class DeclarativeResourceRule extends ResourceRule {
|
|
47
52
|
/**
|
|
48
53
|
* Construct a new regular expression-based declarative resource rule.
|
|
@@ -56,7 +61,7 @@ class DeclarativeResourceRule extends ResourceRule {
|
|
|
56
61
|
* screen when the check fails. Example: "The URL {matchString} did
|
|
57
62
|
* not appear in the target." (Currently, matchString is the only
|
|
58
63
|
* replacement param that is supported.)
|
|
59
|
-
* @param {String} options.regexps an array of strings that encode
|
|
64
|
+
* @param {String[]} options.regexps an array of strings that encode
|
|
60
65
|
* regular expressions to look for. Only one of these regexps needs to
|
|
61
66
|
* match in order to trigger a result from this rule. The first one that
|
|
62
67
|
* matches will be taken, so the order of regular expressions is
|
|
@@ -65,7 +70,7 @@ class DeclarativeResourceRule extends ResourceRule {
|
|
|
65
70
|
* @param {String} [options.sourceLocale] the source locale of this rule
|
|
66
71
|
* @param {String} [options.link] the URL to a web page that explains this
|
|
67
72
|
* rule in more detail
|
|
68
|
-
* @param {
|
|
73
|
+
* @param {Severity} [options.severity] the severity
|
|
69
74
|
* of the Result if this rule matches
|
|
70
75
|
* @param {Array.<String>} [options.locales] the target locales to which this
|
|
71
76
|
* rule applies. If specified, this rule will skip resources that have a
|
|
@@ -20,7 +20,7 @@ class ResourceCamelCase extends ResourceRule {
|
|
|
20
20
|
|
|
21
21
|
this.name = "resource-camel-case";
|
|
22
22
|
this.description = "Ensure that when source strings contain only camel case and no whitespace, then the targets are the same";
|
|
23
|
-
this.link = "https://gihub.com/
|
|
23
|
+
this.link = "https://gihub.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-camel-case.md";
|
|
24
24
|
this.regexps = [
|
|
25
25
|
"^\\s*[a-z\\d]+([A-Z][a-z\\d]+)+\\s*$",
|
|
26
26
|
"^\\s*[A-Z][a-z\\d]+([A-Z][a-z\\d]+)+\\s*$",
|
|
@@ -22,11 +22,14 @@ import Locale from "ilib-locale";
|
|
|
22
22
|
|
|
23
23
|
import ResourceRule from './ResourceRule.js';
|
|
24
24
|
|
|
25
|
+
// type imports
|
|
26
|
+
/** @ignore @typedef {import("ilib-tools-common").Resource} Resource */
|
|
27
|
+
|
|
25
28
|
/** Rule to check that a resource has both source and target elements */
|
|
26
29
|
class ResourceCompleteness extends ResourceRule {
|
|
27
30
|
/** @readonly */ name = "resource-completeness";
|
|
28
31
|
/** @readonly */ description = "Ensure that resources are complete, i.e. have both source and target elements.";
|
|
29
|
-
/** @readonly */ link = "https://github.com/
|
|
32
|
+
/** @readonly */ link = "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-completeness.md";
|
|
30
33
|
|
|
31
34
|
constructor(options) {
|
|
32
35
|
super(options);
|
|
@@ -38,7 +41,7 @@ class ResourceCompleteness extends ResourceRule {
|
|
|
38
41
|
* @param {Object} params a parameters object
|
|
39
42
|
* @param {string} params.source the source string
|
|
40
43
|
* @param {string} params.target the target string
|
|
41
|
-
* @param {
|
|
44
|
+
* @param {Resource} params.resource the resource being checked
|
|
42
45
|
* @param {string} params.file the file where the resource came from
|
|
43
46
|
* @returns {Array.<Result>|undefined} the results
|
|
44
47
|
*/
|
|
@@ -23,12 +23,15 @@ import path from "node:path";
|
|
|
23
23
|
|
|
24
24
|
import ResourceRule from './ResourceRule.js';
|
|
25
25
|
|
|
26
|
+
// type imports
|
|
27
|
+
/** @ignore @typedef {import("ilib-tools-common").Resource} Resource */
|
|
28
|
+
|
|
26
29
|
/** Rule to ensure that Do Not Translate terms have not been translated;
|
|
27
30
|
* i.e., if a DNT term appears in source, it has to appear in target as well */
|
|
28
31
|
class ResourceDNTTerms extends ResourceRule {
|
|
29
32
|
/** @readonly */ name = "resource-dnt-terms";
|
|
30
33
|
/** @readonly */ description = "Ensure that Do Not Translate terms have not been translated.";
|
|
31
|
-
/** @readonly */ link = "https://github.com/
|
|
34
|
+
/** @readonly */ link = "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-dnt-terms.md";
|
|
32
35
|
|
|
33
36
|
/**
|
|
34
37
|
* @protected
|
|
@@ -86,10 +89,11 @@ class ResourceDNTTerms extends ResourceRule {
|
|
|
86
89
|
* Check that if a given resource has a DNT term in the source, then
|
|
87
90
|
* it also exists in the target
|
|
88
91
|
* @override
|
|
89
|
-
* @param {
|
|
90
|
-
* @param {string}
|
|
91
|
-
* @param {
|
|
92
|
-
* @param {
|
|
92
|
+
* @param {Object} props
|
|
93
|
+
* @param {string} props.source the source string
|
|
94
|
+
* @param {string} props.target the target string
|
|
95
|
+
* @param {Resource} props.resource the resource being checked
|
|
96
|
+
* @param {string} props.file the file where the resource came from
|
|
93
97
|
* @returns {Array.<Result>|undefined} the results
|
|
94
98
|
*/
|
|
95
99
|
matchString({ source, target, resource, file }) {
|
|
@@ -98,7 +102,7 @@ class ResourceDNTTerms extends ResourceRule {
|
|
|
98
102
|
rule: this,
|
|
99
103
|
pathName: file,
|
|
100
104
|
locale: resource.getTargetLocale(),
|
|
101
|
-
severity: "error",
|
|
105
|
+
severity: /** @ignore @type {const} */ ("error"),
|
|
102
106
|
description: "A DNT term is missing in target string.",
|
|
103
107
|
};
|
|
104
108
|
|
|
@@ -25,7 +25,7 @@ class ResourceEdgeWhitespace extends ResourceRule {
|
|
|
25
25
|
/** @readonly */ name = "resource-edge-whitespace";
|
|
26
26
|
/** @readonly */ description =
|
|
27
27
|
"Ensure that if there are whitespaces on edges of source string, matching ones are there in target as well";
|
|
28
|
-
/** @readonly */ link = "https://github.com/
|
|
28
|
+
/** @readonly */ link = "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-edge-whitespace.md";
|
|
29
29
|
|
|
30
30
|
constructor() {
|
|
31
31
|
super({});
|
|
@@ -37,7 +37,7 @@ class ResourceICUPluralTranslation extends ResourceRule {
|
|
|
37
37
|
this.name = "resource-icu-plurals-translated";
|
|
38
38
|
this.description = "Ensure that plurals in translated resources are also translated";
|
|
39
39
|
this.sourceLocale = (options && options.sourceLocale) || "en-US";
|
|
40
|
-
this.link = "https://github.com/
|
|
40
|
+
this.link = "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-icu-plurals-translated.md";
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
/**
|
|
@@ -63,7 +63,7 @@ class ResourceICUPlurals extends ResourceRule {
|
|
|
63
63
|
this.name = "resource-icu-plurals";
|
|
64
64
|
this.description = "Ensure that plurals in translated resources have the correct syntax";
|
|
65
65
|
this.sourceLocale = (options && options.sourceLocale) || "en-US";
|
|
66
|
-
this.link = "https://github.com/
|
|
66
|
+
this.link = "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-icu-plurals.md";
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
matchCategories(sourceSelect, targetSelect, locale, resource) {
|
|
@@ -30,7 +30,7 @@ import ResourceRule from './ResourceRule.js';
|
|
|
30
30
|
class ResourceNoTranslation extends ResourceRule {
|
|
31
31
|
#name = "resource-no-translation";
|
|
32
32
|
#description = "Ensure that each resource in a resource file has a proper translation";
|
|
33
|
-
#link = "https://github.com/
|
|
33
|
+
#link = "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-no-translation.md";
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Make a new rule instance.
|
|
@@ -33,7 +33,9 @@ import ResourceRule from './ResourceRule.js';
|
|
|
33
33
|
* @prop {string} quoteEndAlt
|
|
34
34
|
* @prop {RegExp} quotesNative
|
|
35
35
|
* @prop {RegExp} quotesNativeAlt
|
|
36
|
-
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
37
39
|
* @typedef {BaseRegExpCollection} SourceRegExpCollection
|
|
38
40
|
*/
|
|
39
41
|
|
|
@@ -44,8 +46,10 @@ import ResourceRule from './ResourceRule.js';
|
|
|
44
46
|
* @prop {RegExp} quotesAllAlt
|
|
45
47
|
* @prop {string} nonQuoteChars
|
|
46
48
|
* @prop {string} nonQuoteCharsAlt
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @ignore @typedef {BaseRegExpCollection & ExtendedRegExpCollection} TargetRegExpCollection
|
|
49
53
|
*/
|
|
50
54
|
|
|
51
55
|
/**
|
|
@@ -99,7 +103,7 @@ class ResourceQuoteStyle extends ResourceRule {
|
|
|
99
103
|
this.name = "resource-quote-style";
|
|
100
104
|
this.description = "Ensure that the proper quote characters are used in translated resources";
|
|
101
105
|
this.sourceLocale = (options && options.sourceLocale) || "en-US";
|
|
102
|
-
this.link = "https://github.com/
|
|
106
|
+
this.link = "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-quote-style.md";
|
|
103
107
|
|
|
104
108
|
if (options?.param === "localeOnly") {
|
|
105
109
|
// only localized quotes are allowed in the target string
|
|
@@ -20,7 +20,7 @@ class ResourceSnakeCase extends ResourceRule {
|
|
|
20
20
|
|
|
21
21
|
this.name = "resource-snake-case";
|
|
22
22
|
this.description = "Ensure that when source strings contain only snake case and no whitespace, then the targets are the same";
|
|
23
|
-
this.link = "https://gihub.com/
|
|
23
|
+
this.link = "https://gihub.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-snake-case.md",
|
|
24
24
|
this.regexps = [
|
|
25
25
|
"^\\s*[a-zA-Z0-9]*(_[a-zA-Z0-9]+)+\\s*$",
|
|
26
26
|
"^\\s*[a-zA-Z0-9]+(_[a-zA-Z0-9]+)*_\\s*$"
|
|
@@ -38,7 +38,7 @@ export class ResourceSourceICUPluralCategories extends ResourceRule {
|
|
|
38
38
|
/** @override */
|
|
39
39
|
description = "Verify that categories of an ICU plural in the source of a Resource are valid";
|
|
40
40
|
/** @override */
|
|
41
|
-
link = "https://github.com/
|
|
41
|
+
link = "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-icu-plurals.md";
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* @param {any} [opts]
|
|
@@ -38,7 +38,7 @@ export class ResourceSourceICUPluralParams extends ResourceRule {
|
|
|
38
38
|
/** @override */
|
|
39
39
|
description = "Verify that the 'one' category of an ICU plural contains the same replacement parameters as the 'other' category.";
|
|
40
40
|
/** @override */
|
|
41
|
-
link = "https://github.com/
|
|
41
|
+
link = "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/source-icu-plural-params.md";
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* @param {any} [opts]
|
|
@@ -32,7 +32,7 @@ export class ResourceSourceICUPluralSyntax extends ResourceRule {
|
|
|
32
32
|
/** @override */
|
|
33
33
|
description = "Verify that syntax of an ICU plural in the source of a Resource is valid";
|
|
34
34
|
/** @override */
|
|
35
|
-
link = "https://github.com/
|
|
35
|
+
link = "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-icu-plurals.md";
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* @param {any} [opts]
|
|
@@ -47,7 +47,7 @@ export class ResourceSourceICUUnexplainedParams extends ResourceRule {
|
|
|
47
47
|
"Check if replacement parameters used in the source string are explained in the comments for translators.";
|
|
48
48
|
/** @override */
|
|
49
49
|
link =
|
|
50
|
-
"https://github.com/
|
|
50
|
+
"https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/source-icu-unexplained-params.md";
|
|
51
51
|
|
|
52
52
|
/** @param {any} [opts] */
|
|
53
53
|
constructor(opts) {
|
|
@@ -142,7 +142,7 @@ export class ResourceSourceICUUnexplainedParams extends ResourceRule {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
/**
|
|
145
|
-
* @typedef {{
|
|
145
|
+
* @ignore @typedef {{
|
|
146
146
|
* element: MessageFormatElement;
|
|
147
147
|
* parent: undefined | ICUAstNode;
|
|
148
148
|
* }} ICUAstNode
|
|
@@ -156,7 +156,7 @@ export class ResourceSourceICUUnexplainedParams extends ResourceRule {
|
|
|
156
156
|
*/
|
|
157
157
|
traverseIcuAst(
|
|
158
158
|
/** @type {MessageFormatElement[]} */ message,
|
|
159
|
-
/** @type {(node: ICUAstNode) => void} */ callback,
|
|
159
|
+
/** @ignore @type {(node: ICUAstNode) => void} */ callback,
|
|
160
160
|
/** @type {ICUAstNode | undefined} */ parent
|
|
161
161
|
) {
|
|
162
162
|
for (const element of message) {
|
|
@@ -49,7 +49,7 @@ class ResourceStateChecker extends Rule {
|
|
|
49
49
|
this.name = "resource-state-checker";
|
|
50
50
|
this.description = "Ensure that resources have a particular state.";
|
|
51
51
|
this.sourceLocale = (options && options.sourceLocale) || "en-US";
|
|
52
|
-
this.link = "https://github.com/
|
|
52
|
+
this.link = "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-state-checker.md";
|
|
53
53
|
|
|
54
54
|
if (options) {
|
|
55
55
|
if (typeof(options.param) === "string") {
|
|
@@ -38,7 +38,7 @@ class ResourceUniqueKeys extends Rule {
|
|
|
38
38
|
this.name = "resource-unique-keys";
|
|
39
39
|
this.description = "Ensure that the keys are unique within a locale across all resource files";
|
|
40
40
|
this.sourceLocale = (options && options.sourceLocale) || "en-US";
|
|
41
|
-
this.link = "https://github.com/
|
|
41
|
+
this.link = "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-unique-keys.md";
|
|
42
42
|
this.ts = new TranslationSet();
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -89,4 +89,4 @@ class ResourceUniqueKeys extends Rule {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
export default ResourceUniqueKeys;
|
|
92
|
+
export default ResourceUniqueKeys;
|
package/src/rules/ResourceXML.js
CHANGED
|
@@ -41,7 +41,7 @@ class ResourceXML extends ResourceRule {
|
|
|
41
41
|
this.name = "resource-xml";
|
|
42
42
|
this.description = "Ensure that XML in translated resources match the source";
|
|
43
43
|
this.sourceLocale = (options && options.sourceLocale) || "en-US";
|
|
44
|
-
this.link = "https://github.com/
|
|
44
|
+
this.link = "https://github.com/iLib-js/ilib-mono/blob/main/packages/ilib-lint/docs/resource-xml.md";
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/**
|
|
@@ -241,4 +241,4 @@ class ResourceXML extends ResourceRule {
|
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
-
export default ResourceXML;
|
|
244
|
+
export default ResourceXML;
|
package/src/rules/utils.js
CHANGED
|
@@ -19,8 +19,11 @@
|
|
|
19
19
|
|
|
20
20
|
import { IntlMessageFormat } from 'intl-messageformat';
|
|
21
21
|
|
|
22
|
+
// type imports
|
|
23
|
+
/** @ignore @typedef {import("@formatjs/icu-messageformat-parser").MessageFormatElement} MessageFormatElement */
|
|
24
|
+
|
|
22
25
|
/** @returns {string} */
|
|
23
|
-
function concatIntlAstText(/** @type {
|
|
26
|
+
function concatIntlAstText(/** @type {MessageFormatElement[]} */ astElements) {
|
|
24
27
|
return astElements
|
|
25
28
|
.map((element) => {
|
|
26
29
|
switch (element.type) {
|