ilib-lint 1.0.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.
- package/LICENSE +201 -0
- package/README.md +231 -0
- package/docs/AnsiConsoleFormatter.html +467 -0
- package/docs/Formatter.html +577 -0
- package/docs/Formatter.js.html +135 -0
- package/docs/FormatterFactory.html +191 -0
- package/docs/FormatterFactory.js.html +109 -0
- package/docs/Parser.html +483 -0
- package/docs/Parser.js.html +122 -0
- package/docs/ParserFactory.js.html +109 -0
- package/docs/Plugin.html +847 -0
- package/docs/Plugin.js.html +168 -0
- package/docs/PluginManager.html +541 -0
- package/docs/PluginManager.js.html +125 -0
- package/docs/ResourceICUPlurals.html +278 -0
- package/docs/ResourceQuoteStyle.html +278 -0
- package/docs/ResourceRegExpChecker.html +295 -0
- package/docs/ResourceUniqueKeys.html +278 -0
- package/docs/Result.html +263 -0
- package/docs/Result.js.html +130 -0
- package/docs/Rule.html +774 -0
- package/docs/Rule.js.html +230 -0
- package/docs/RuleSet.html +760 -0
- package/docs/RuleSet.js.html +153 -0
- package/docs/SourceFile.html +826 -0
- package/docs/SourceFile.js.html +232 -0
- package/docs/XliffParser.html +396 -0
- package/docs/XliffPlugin.html +472 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- package/docs/formatters_AnsiConsoleFormatter.js.html +147 -0
- package/docs/global.html +448 -0
- package/docs/ilibLint.md +1013 -0
- package/docs/index.html +81 -0
- package/docs/plugins_XliffParser.js.html +129 -0
- package/docs/plugins_XliffPlugin.js.html +129 -0
- package/docs/rules_ResourceICUPlurals.js.html +297 -0
- package/docs/rules_ResourceQuoteStyle.js.html +238 -0
- package/docs/rules_ResourceRegExpChecker.js.html +248 -0
- package/docs/rules_ResourceUniqueKeys.js.html +144 -0
- package/docs/scripts/collapse.js +20 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/nav.js +12 -0
- package/docs/scripts/polyfill.js +4 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/scripts/prettify/lang-css.js +2 -0
- package/docs/scripts/prettify/prettify.js +28 -0
- package/docs/scripts/search.js +83 -0
- package/docs/styles/jsdoc.css +765 -0
- package/docs/styles/prettify.css +79 -0
- package/docs/walk.js.html +214 -0
- package/log4js.json +21 -0
- package/package.json +83 -0
- package/src/Formatter.js +66 -0
- package/src/FormatterFactory.js +41 -0
- package/src/Parser.js +53 -0
- package/src/ParserFactory.js +41 -0
- package/src/Plugin.js +99 -0
- package/src/PluginManager.js +56 -0
- package/src/Result.js +62 -0
- package/src/Rule.js +162 -0
- package/src/RuleSet.js +84 -0
- package/src/SourceFile.js +163 -0
- package/src/formatters/AnsiConsoleFormatter.js +78 -0
- package/src/index.js +213 -0
- package/src/plugins/XliffParser.js +60 -0
- package/src/plugins/XliffPlugin.js +60 -0
- package/src/rules/ResourceICUPlurals.js +229 -0
- package/src/rules/ResourceQuoteStyle.js +170 -0
- package/src/rules/ResourceRegExpChecker.js +179 -0
- package/src/rules/ResourceUniqueKeys.js +76 -0
- package/src/rules/utils.js +78 -0
- package/src/walk.js +146 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>rules/ResourceRegExpChecker.js - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
18
|
+
</head>
|
|
19
|
+
<body>
|
|
20
|
+
|
|
21
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
22
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
23
|
+
<div class="navicon"></div>
|
|
24
|
+
</label>
|
|
25
|
+
|
|
26
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
27
|
+
|
|
28
|
+
<nav >
|
|
29
|
+
|
|
30
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AnsiConsoleFormatter.html">AnsiConsoleFormatter</a><ul class='methods'><li data-type='method'><a href="AnsiConsoleFormatter.html#format">format</a></li><li data-type='method'><a href="AnsiConsoleFormatter.html#getDescription">getDescription</a></li></ul></li><li><a href="Formatter.html">Formatter</a><ul class='methods'><li data-type='method'><a href="Formatter.html#format">format</a></li><li data-type='method'><a href="Formatter.html#getDescription">getDescription</a></li><li data-type='method'><a href="Formatter.html#getName">getName</a></li></ul></li><li><a href="FormatterFactory.html">FormatterFactory</a></li><li><a href="Parser.html">Parser</a><ul class='methods'><li data-type='method'><a href="Parser.html#getResources">getResources</a></li><li data-type='method'><a href="Parser.html#init">init</a></li><li data-type='method'><a href="Parser.html#parse">parse</a></li></ul></li><li><a href="Plugin.html">Plugin</a><ul class='methods'><li data-type='method'><a href="Plugin.html#getExtensions">getExtensions</a></li><li data-type='method'><a href="Plugin.html#getFormatters">getFormatters</a></li><li data-type='method'><a href="Plugin.html#getParsers">getParsers</a></li><li data-type='method'><a href="Plugin.html#getRules">getRules</a></li><li data-type='method'><a href="Plugin.html#getType">getType</a></li><li data-type='method'><a href="Plugin.html#init">init</a></li></ul></li><li><a href="PluginManager.html">PluginManager</a><ul class='methods'><li data-type='method'><a href="PluginManager.html#getHandlers">getHandlers</a></li><li data-type='method'><a href="PluginManager.html#load">load</a></li></ul></li><li><a href="ResourceICUPlurals.html">ResourceICUPlurals</a><ul class='methods'><li data-type='method'><a href="ResourceICUPlurals.html#match">match</a></li></ul></li><li><a href="ResourceQuoteStyle.html">ResourceQuoteStyle</a><ul class='methods'><li data-type='method'><a href="ResourceQuoteStyle.html#match">match</a></li></ul></li><li><a href="ResourceRegExpChecker.html">ResourceRegExpChecker</a><ul class='methods'><li data-type='method'><a href="ResourceRegExpChecker.html#match">match</a></li></ul></li><li><a href="ResourceUniqueKeys.html">ResourceUniqueKeys</a><ul class='methods'><li data-type='method'><a href="ResourceUniqueKeys.html#match">match</a></li></ul></li><li><a href="Result.html">Result</a></li><li><a href="Rule.html">Rule</a><ul class='methods'><li data-type='method'><a href="Rule.html#getDescription">getDescription</a></li><li data-type='method'><a href="Rule.html#getName">getName</a></li><li data-type='method'><a href="Rule.html#getRuleType">getRuleType</a></li><li data-type='method'><a href="Rule.html#match">match</a></li></ul></li><li><a href="RuleSet.html">RuleSet</a><ul class='methods'><li data-type='method'><a href="RuleSet.html#addRule">addRule</a></li><li data-type='method'><a href="RuleSet.html#getRule">getRule</a></li><li data-type='method'><a href="RuleSet.html#getRules">getRules</a></li><li data-type='method'><a href="RuleSet.html#getSize">getSize</a></li></ul></li><li><a href="SourceFile.html">SourceFile</a><ul class='methods'><li data-type='method'><a href="SourceFile.html#findIssues">findIssues</a></li><li data-type='method'><a href="SourceFile.html#getFilePath">getFilePath</a></li><li data-type='method'><a href="SourceFile.html#getLocaleFromPath">getLocaleFromPath</a></li><li data-type='method'><a href="SourceFile.html#getType">getType</a></li><li data-type='method'><a href="SourceFile.html#parse">parse</a></li></ul></li><li><a href="XliffParser.html">XliffParser</a><ul class='methods'><li data-type='method'><a href="XliffParser.html#getResources">getResources</a></li><li data-type='method'><a href="XliffParser.html#parse">parse</a></li></ul></li><li><a href="XliffPlugin.html">XliffPlugin</a><ul class='methods'><li data-type='method'><a href="XliffPlugin.html#getExtensions">getExtensions</a></li><li data-type='method'><a href="XliffPlugin.html#getParsers">getParsers</a></li><li data-type='method'><a href="XliffPlugin.html#getType">getType</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#ParserFactory">ParserFactory</a></li><li><a href="global.html#walk">walk</a></li></ul>
|
|
31
|
+
</nav>
|
|
32
|
+
|
|
33
|
+
<div id="main">
|
|
34
|
+
|
|
35
|
+
<h1 class="page-title">rules/ResourceRegExpChecker.js</h1>
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
<section>
|
|
44
|
+
<article>
|
|
45
|
+
<pre class="prettyprint source linenums"><code>/*
|
|
46
|
+
* ResourceRegExpChecker.js - rule to check if URLs in the source string also
|
|
47
|
+
* appear in the target string
|
|
48
|
+
*
|
|
49
|
+
* Copyright © 2022 JEDLSoft
|
|
50
|
+
*
|
|
51
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
52
|
+
* you may not use this file except in compliance with the License.
|
|
53
|
+
* You may obtain a copy of the License at
|
|
54
|
+
*
|
|
55
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
56
|
+
*
|
|
57
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
58
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
59
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
60
|
+
*
|
|
61
|
+
* See the License for the specific language governing permissions and
|
|
62
|
+
* limitations under the License.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
import Rule from '../Rule.js';
|
|
66
|
+
import Result from '../Result.js';
|
|
67
|
+
import { stripPlurals } from './utils.js';
|
|
68
|
+
|
|
69
|
+
function findMissing(source, target) {
|
|
70
|
+
let missing = [];
|
|
71
|
+
for (var i = 0; i < source.length; i++) {
|
|
72
|
+
if (target.indexOf(source[i]) < 0) {
|
|
73
|
+
missing.push(source[i]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return missing;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @class Resource checker class that checks that any regular expressions
|
|
81
|
+
* that matches in the source also appears in the translation.
|
|
82
|
+
*/
|
|
83
|
+
class ResourceRegExpChecker extends Rule {
|
|
84
|
+
/**
|
|
85
|
+
* Construct a new regular expression-based resource checker.
|
|
86
|
+
*
|
|
87
|
+
* The options must contain the following required properties:
|
|
88
|
+
*
|
|
89
|
+
* - name - a unique name for this rule
|
|
90
|
+
* - description - a one-line description of what this rule checks for.
|
|
91
|
+
* Example: "Check that URLs in the source also appear in the target"
|
|
92
|
+
* - note - a one-line note that will be printed on screen when the
|
|
93
|
+
* check fails. Example: "The URL {matchString} did not appear in the
|
|
94
|
+
* the target." (Currently, matchString is the only replacement
|
|
95
|
+
* param that is supported.)
|
|
96
|
+
* - regexps - an array of strings that encode regular expressions to
|
|
97
|
+
* look for
|
|
98
|
+
*/
|
|
99
|
+
constructor(options) {
|
|
100
|
+
super(options);
|
|
101
|
+
|
|
102
|
+
if (!options || !options.name || !options.description || !options.note || !options.regexps) {
|
|
103
|
+
throw "Missing required options for the ResourceRegExpChecker constructor";
|
|
104
|
+
}
|
|
105
|
+
["name", "description", "regexps", "note", "sourceLocale"].forEach(prop => {
|
|
106
|
+
this[prop] = options[prop];
|
|
107
|
+
});
|
|
108
|
+
this.sourceLocale = this.sourceLocale || "en-US";
|
|
109
|
+
|
|
110
|
+
// this may throw if you got to the syntax wrong:
|
|
111
|
+
this.re = this.regexps.map(regexp => new RegExp(regexp, "g"));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
getRuleType() {
|
|
115
|
+
return "resource";
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @override
|
|
120
|
+
*/
|
|
121
|
+
match(options) {
|
|
122
|
+
const { locale, resource, file } = options || {};
|
|
123
|
+
const _this = this;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @private
|
|
127
|
+
*/
|
|
128
|
+
function checkString(re, src, tar) {
|
|
129
|
+
re.lastIndex = 0;
|
|
130
|
+
let sourceMatches = [];
|
|
131
|
+
const strippedSrc = stripPlurals(src);
|
|
132
|
+
const strippedTar = stripPlurals(tar);
|
|
133
|
+
|
|
134
|
+
let match = re.exec(strippedSrc);
|
|
135
|
+
while (match) {
|
|
136
|
+
sourceMatches.push(match[0]);
|
|
137
|
+
match = re.exec(strippedSrc);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (sourceMatches.length > 0) {
|
|
141
|
+
// contains URLs, so check the target
|
|
142
|
+
re.lastIndex = 0;
|
|
143
|
+
let targetMatches = [];
|
|
144
|
+
match = re.exec(strippedTar);
|
|
145
|
+
while (match) {
|
|
146
|
+
targetMatches.push(match[0]);
|
|
147
|
+
match = re.exec(strippedTar);
|
|
148
|
+
}
|
|
149
|
+
const missing = findMissing(sourceMatches, targetMatches);
|
|
150
|
+
if (missing.length > 0) {
|
|
151
|
+
return missing.map(missing => {
|
|
152
|
+
let value = {
|
|
153
|
+
severity: "error",
|
|
154
|
+
id: resource.getKey(),
|
|
155
|
+
source: src,
|
|
156
|
+
rule: _this,
|
|
157
|
+
pathName: file,
|
|
158
|
+
highlight:`Target: ${tar}<e0></e0>`,
|
|
159
|
+
description: _this.note.replace(/\{matchString\}/g, missing)
|
|
160
|
+
};
|
|
161
|
+
if (typeof(options.lineNumber) !== 'undefined') {
|
|
162
|
+
value.lineNumber = options.lineNumber;
|
|
163
|
+
}
|
|
164
|
+
return new Result(value);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function checkRegExps(src, tar) {
|
|
171
|
+
let results = [];
|
|
172
|
+
_this.re.forEach(re => {
|
|
173
|
+
results = results.concat(checkString(re, src, tar));
|
|
174
|
+
});
|
|
175
|
+
results = results.filter(result => result);
|
|
176
|
+
return results && results.length ? results : undefined;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
switch (resource.getType()) {
|
|
180
|
+
case 'string':
|
|
181
|
+
const tarString = resource.getTarget();
|
|
182
|
+
if (tarString) {
|
|
183
|
+
return checkRegExps(resource.getSource(), tarString);
|
|
184
|
+
}
|
|
185
|
+
break;
|
|
186
|
+
|
|
187
|
+
case 'array':
|
|
188
|
+
const srcArray = resource.getSource();
|
|
189
|
+
const tarArray = resource.getTarget();
|
|
190
|
+
if (tarArray) {
|
|
191
|
+
return srcArray.map((item, i) => {
|
|
192
|
+
if (i < tarArray.length && tarArray[i]) {
|
|
193
|
+
return checkRegExps(srcArray[i], tarArray[i]);
|
|
194
|
+
}
|
|
195
|
+
}).filter(element => {
|
|
196
|
+
return element;
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
break;
|
|
200
|
+
|
|
201
|
+
case 'plural':
|
|
202
|
+
const srcPlural = resource.getSource();
|
|
203
|
+
const tarPlural = resource.getTarget();
|
|
204
|
+
if (tarPlural) {
|
|
205
|
+
const hasQuotes = categories.find(category => {
|
|
206
|
+
return (srcPlural[category] && srcPlural[category].contains(srcQuote));
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
if (hasQuotes) {
|
|
210
|
+
return categories.map(category => {
|
|
211
|
+
return checkRegExps(srcPlural.other, tarPlural[category]);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// no match
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export default ResourceRegExpChecker;
|
|
224
|
+
</code></pre>
|
|
225
|
+
</article>
|
|
226
|
+
</section>
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
</div>
|
|
234
|
+
|
|
235
|
+
<br class="clear">
|
|
236
|
+
|
|
237
|
+
<footer>
|
|
238
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Mon Dec 19 2022 15:00:46 GMT-0800 (Pacific Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
239
|
+
</footer>
|
|
240
|
+
|
|
241
|
+
<script>prettyPrint();</script>
|
|
242
|
+
<script src="scripts/polyfill.js"></script>
|
|
243
|
+
<script src="scripts/linenumber.js"></script>
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
</body>
|
|
248
|
+
</html>
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>rules/ResourceUniqueKeys.js - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
18
|
+
</head>
|
|
19
|
+
<body>
|
|
20
|
+
|
|
21
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
22
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
23
|
+
<div class="navicon"></div>
|
|
24
|
+
</label>
|
|
25
|
+
|
|
26
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
27
|
+
|
|
28
|
+
<nav >
|
|
29
|
+
|
|
30
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AnsiConsoleFormatter.html">AnsiConsoleFormatter</a><ul class='methods'><li data-type='method'><a href="AnsiConsoleFormatter.html#format">format</a></li><li data-type='method'><a href="AnsiConsoleFormatter.html#getDescription">getDescription</a></li></ul></li><li><a href="Formatter.html">Formatter</a><ul class='methods'><li data-type='method'><a href="Formatter.html#format">format</a></li><li data-type='method'><a href="Formatter.html#getDescription">getDescription</a></li><li data-type='method'><a href="Formatter.html#getName">getName</a></li></ul></li><li><a href="FormatterFactory.html">FormatterFactory</a></li><li><a href="Parser.html">Parser</a><ul class='methods'><li data-type='method'><a href="Parser.html#getResources">getResources</a></li><li data-type='method'><a href="Parser.html#init">init</a></li><li data-type='method'><a href="Parser.html#parse">parse</a></li></ul></li><li><a href="Plugin.html">Plugin</a><ul class='methods'><li data-type='method'><a href="Plugin.html#getExtensions">getExtensions</a></li><li data-type='method'><a href="Plugin.html#getFormatters">getFormatters</a></li><li data-type='method'><a href="Plugin.html#getParsers">getParsers</a></li><li data-type='method'><a href="Plugin.html#getRules">getRules</a></li><li data-type='method'><a href="Plugin.html#getType">getType</a></li><li data-type='method'><a href="Plugin.html#init">init</a></li></ul></li><li><a href="PluginManager.html">PluginManager</a><ul class='methods'><li data-type='method'><a href="PluginManager.html#getHandlers">getHandlers</a></li><li data-type='method'><a href="PluginManager.html#load">load</a></li></ul></li><li><a href="ResourceICUPlurals.html">ResourceICUPlurals</a><ul class='methods'><li data-type='method'><a href="ResourceICUPlurals.html#match">match</a></li></ul></li><li><a href="ResourceQuoteStyle.html">ResourceQuoteStyle</a><ul class='methods'><li data-type='method'><a href="ResourceQuoteStyle.html#match">match</a></li></ul></li><li><a href="ResourceRegExpChecker.html">ResourceRegExpChecker</a><ul class='methods'><li data-type='method'><a href="ResourceRegExpChecker.html#match">match</a></li></ul></li><li><a href="ResourceUniqueKeys.html">ResourceUniqueKeys</a><ul class='methods'><li data-type='method'><a href="ResourceUniqueKeys.html#match">match</a></li></ul></li><li><a href="Result.html">Result</a></li><li><a href="Rule.html">Rule</a><ul class='methods'><li data-type='method'><a href="Rule.html#getDescription">getDescription</a></li><li data-type='method'><a href="Rule.html#getName">getName</a></li><li data-type='method'><a href="Rule.html#getRuleType">getRuleType</a></li><li data-type='method'><a href="Rule.html#match">match</a></li></ul></li><li><a href="RuleSet.html">RuleSet</a><ul class='methods'><li data-type='method'><a href="RuleSet.html#addRule">addRule</a></li><li data-type='method'><a href="RuleSet.html#getRule">getRule</a></li><li data-type='method'><a href="RuleSet.html#getRules">getRules</a></li><li data-type='method'><a href="RuleSet.html#getSize">getSize</a></li></ul></li><li><a href="SourceFile.html">SourceFile</a><ul class='methods'><li data-type='method'><a href="SourceFile.html#findIssues">findIssues</a></li><li data-type='method'><a href="SourceFile.html#getFilePath">getFilePath</a></li><li data-type='method'><a href="SourceFile.html#getLocaleFromPath">getLocaleFromPath</a></li><li data-type='method'><a href="SourceFile.html#getType">getType</a></li><li data-type='method'><a href="SourceFile.html#parse">parse</a></li></ul></li><li><a href="XliffParser.html">XliffParser</a><ul class='methods'><li data-type='method'><a href="XliffParser.html#getResources">getResources</a></li><li data-type='method'><a href="XliffParser.html#parse">parse</a></li></ul></li><li><a href="XliffPlugin.html">XliffPlugin</a><ul class='methods'><li data-type='method'><a href="XliffPlugin.html#getExtensions">getExtensions</a></li><li data-type='method'><a href="XliffPlugin.html#getParsers">getParsers</a></li><li data-type='method'><a href="XliffPlugin.html#getType">getType</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#ParserFactory">ParserFactory</a></li><li><a href="global.html#walk">walk</a></li></ul>
|
|
31
|
+
</nav>
|
|
32
|
+
|
|
33
|
+
<div id="main">
|
|
34
|
+
|
|
35
|
+
<h1 class="page-title">rules/ResourceUniqueKeys.js</h1>
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
<section>
|
|
44
|
+
<article>
|
|
45
|
+
<pre class="prettyprint source linenums"><code>/*
|
|
46
|
+
* ResourceUniqueKeys.js - rule to check quotes in the target string
|
|
47
|
+
*
|
|
48
|
+
* Copyright © 2022 JEDLSoft
|
|
49
|
+
*
|
|
50
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
51
|
+
* you may not use this file except in compliance with the License.
|
|
52
|
+
* You may obtain a copy of the License at
|
|
53
|
+
*
|
|
54
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
55
|
+
*
|
|
56
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
57
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
58
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
59
|
+
*
|
|
60
|
+
* See the License for the specific language governing permissions and
|
|
61
|
+
* limitations under the License.
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
import LocaleInfo from 'ilib-localeinfo';
|
|
65
|
+
import { TranslationSet } from 'ilib-tools-common';
|
|
66
|
+
|
|
67
|
+
import Rule from '../Rule.js';
|
|
68
|
+
import Result from '../Result.js';
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @class Represent an ilib-lint rule.
|
|
72
|
+
*/
|
|
73
|
+
class ResourceUniqueKeys extends Rule {
|
|
74
|
+
constructor(options) {
|
|
75
|
+
super(options);
|
|
76
|
+
this.name = "resource-unique-keys";
|
|
77
|
+
this.description = "Ensure that the keys are unique within a locale across all resource files";
|
|
78
|
+
this.sourceLocale = (options && options.sourceLocale) || "en-US";
|
|
79
|
+
|
|
80
|
+
this.ts = new TranslationSet();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
getRuleType() {
|
|
84
|
+
return "resource";
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @override
|
|
89
|
+
*/
|
|
90
|
+
match(options) {
|
|
91
|
+
const { locale, resource, file } = options || {};
|
|
92
|
+
|
|
93
|
+
const hash = resource.hashKey();
|
|
94
|
+
const other = this.ts.get(hash);
|
|
95
|
+
|
|
96
|
+
if (other) {
|
|
97
|
+
let value = {
|
|
98
|
+
severity: "error",
|
|
99
|
+
id: resource.getKey(),
|
|
100
|
+
rule: this,
|
|
101
|
+
pathName: file,
|
|
102
|
+
highlight: `Also defined in this file: ${other.resfile}`,
|
|
103
|
+
description: `Key is not unique within locale ${locale}.`,
|
|
104
|
+
locale
|
|
105
|
+
};
|
|
106
|
+
if (typeof(options.lineNumber) !== 'undefined') {
|
|
107
|
+
value.lineNumber = options.lineNumber;
|
|
108
|
+
}
|
|
109
|
+
return new Result(value);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
resource.resfile = file;
|
|
113
|
+
this.ts.add(resource);
|
|
114
|
+
|
|
115
|
+
// no result
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export default ResourceUniqueKeys;</code></pre>
|
|
121
|
+
</article>
|
|
122
|
+
</section>
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
</div>
|
|
130
|
+
|
|
131
|
+
<br class="clear">
|
|
132
|
+
|
|
133
|
+
<footer>
|
|
134
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Mon Dec 19 2022 15:00:46 GMT-0800 (Pacific Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
135
|
+
</footer>
|
|
136
|
+
|
|
137
|
+
<script>prettyPrint();</script>
|
|
138
|
+
<script src="scripts/polyfill.js"></script>
|
|
139
|
+
<script src="scripts/linenumber.js"></script>
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
</body>
|
|
144
|
+
</html>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function hideAllButCurrent(){
|
|
2
|
+
//by default all submenut items are hidden
|
|
3
|
+
//but we need to rehide them for search
|
|
4
|
+
document.querySelectorAll("nav > ul > li > ul li").forEach(function(parent) {
|
|
5
|
+
parent.style.display = "none";
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
//only current page (if it exists) should be opened
|
|
9
|
+
var file = window.location.pathname.split("/").pop().replace(/\.html/, '');
|
|
10
|
+
document.querySelectorAll("nav > ul > li > a").forEach(function(parent) {
|
|
11
|
+
var href = parent.attributes.href.value.replace(/\.html/, '');
|
|
12
|
+
if (file === href) {
|
|
13
|
+
parent.parentNode.querySelectorAll("ul li").forEach(function(elem) {
|
|
14
|
+
elem.style.display = "block";
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
hideAllButCurrent();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*global document */
|
|
2
|
+
(function() {
|
|
3
|
+
var source = document.getElementsByClassName('prettyprint source linenums');
|
|
4
|
+
var i = 0;
|
|
5
|
+
var lineNumber = 0;
|
|
6
|
+
var lineId;
|
|
7
|
+
var lines;
|
|
8
|
+
var totalLines;
|
|
9
|
+
var anchorHash;
|
|
10
|
+
|
|
11
|
+
if (source && source[0]) {
|
|
12
|
+
anchorHash = document.location.hash.substring(1);
|
|
13
|
+
lines = source[0].getElementsByTagName('li');
|
|
14
|
+
totalLines = lines.length;
|
|
15
|
+
|
|
16
|
+
for (; i < totalLines; i++) {
|
|
17
|
+
lineNumber++;
|
|
18
|
+
lineId = 'line' + lineNumber;
|
|
19
|
+
lines[i].id = lineId;
|
|
20
|
+
if (lineId === anchorHash) {
|
|
21
|
+
lines[i].className += ' selected';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
})();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function scrollToNavItem() {
|
|
2
|
+
var path = window.location.href.split('/').pop().replace(/\.html/, '');
|
|
3
|
+
document.querySelectorAll('nav a').forEach(function(link) {
|
|
4
|
+
var href = link.attributes.href.value.replace(/\.html/, '');
|
|
5
|
+
if (path === href) {
|
|
6
|
+
link.scrollIntoView({block: 'center'});
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
scrollToNavItem();
|