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,230 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>Rule.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">Rule.js</h1>
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
<section>
|
|
44
|
+
<article>
|
|
45
|
+
<pre class="prettyprint source linenums"><code>/*
|
|
46
|
+
* Rule.js - Represent an ilib-lint rule
|
|
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
|
+
/**
|
|
65
|
+
* @class Represent an ilib-lint rule.
|
|
66
|
+
* @abstract
|
|
67
|
+
*/
|
|
68
|
+
class Rule {
|
|
69
|
+
/**
|
|
70
|
+
* Construct an ilib-lint rule. Rules in plugins should implement this
|
|
71
|
+
* abstract class.
|
|
72
|
+
*/
|
|
73
|
+
constructor() {
|
|
74
|
+
if (this.constructor === Rule) {
|
|
75
|
+
throw new Error("Cannot instantiate abstract class Rule!");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get the name of the rule. This should be a string with a dash-separated
|
|
81
|
+
* set of words (kebab or dash case). Example: "resource-match-whitespace"
|
|
82
|
+
*
|
|
83
|
+
* @returns {String} the name of this rule
|
|
84
|
+
*/
|
|
85
|
+
getName() {
|
|
86
|
+
// make sure to define this.name in your implementation
|
|
87
|
+
return this.name;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Return a general description of the type of problems that this rule is
|
|
92
|
+
* testing for. This description is not related to particular matches, so
|
|
93
|
+
* it cannot be more specific. Examples:
|
|
94
|
+
*
|
|
95
|
+
* "translation should use the appropriate quote style"
|
|
96
|
+
* "parameters to the translation wrapper function must not be concatenated"
|
|
97
|
+
* "translation should match the whitespace of the source string"
|
|
98
|
+
*
|
|
99
|
+
* @returns {String} a general description of the type of problems that this rule is
|
|
100
|
+
* testing for
|
|
101
|
+
*/
|
|
102
|
+
getDescription() {
|
|
103
|
+
return this.description;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Return the type of this rule. Rules can be organized into the following
|
|
108
|
+
* types:
|
|
109
|
+
*
|
|
110
|
+
* - A resource rule. This checks a translated resource with a source string
|
|
111
|
+
* and a translation to a given locale. eg. a rule that checks that
|
|
112
|
+
* substitution parameters that exist in the source string also are
|
|
113
|
+
* given in the target string.
|
|
114
|
+
* - A line rule. This rule checks single lines of a file. eg. a rule to
|
|
115
|
+
* check the parameters to a function call.
|
|
116
|
+
* - A multiline rule. This rule checks multiple lines at once to find
|
|
117
|
+
* problems that may span multiple lines. For example, a rule to enforce
|
|
118
|
+
* a policy that all translatable strings in a source file have an appropriate
|
|
119
|
+
* translator's comment on them.
|
|
120
|
+
* - A multifile rule. This rule checks problems across multiple files. eg.
|
|
121
|
+
* a rule to check that ids for translatable strings are unique across all
|
|
122
|
+
* files.
|
|
123
|
+
*
|
|
124
|
+
* @returns {String} a string with either "resource", "line", "multiline", or
|
|
125
|
+
* "multifile".
|
|
126
|
+
*/
|
|
127
|
+
getRuleType() {
|
|
128
|
+
// default rule type. If your rule is different, override this method.
|
|
129
|
+
return "line";
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
getSourceLocale() {
|
|
133
|
+
return this.sourceLocale || "en-US";
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Return whether or not this rule matches the input. The options object can
|
|
138
|
+
* contain any of the following properties:
|
|
139
|
+
*
|
|
140
|
+
* <ul>
|
|
141
|
+
* <li>locale - the locale against which this rule should be checked. Some rules
|
|
142
|
+
* are locale-sensitive, others not.
|
|
143
|
+
* <li>resource - the resource to test this rule against. For resource rules, this
|
|
144
|
+
* is a required property.
|
|
145
|
+
* <li>line - a single line of a file to test this rule against (for line rules)
|
|
146
|
+
* <li>lines - all the lines of a file to test this rule against (for multiline rules
|
|
147
|
+
* and multifile rules)
|
|
148
|
+
* <li>pathName - the name of the current file being matched in multifile rules.
|
|
149
|
+
* <li>parameters - (optional) parameters for this rule from the configuration file
|
|
150
|
+
* </ul>
|
|
151
|
+
*
|
|
152
|
+
* The return value from this method when a rule matches is an object with the
|
|
153
|
+
* following properties:
|
|
154
|
+
*
|
|
155
|
+
* <ul>
|
|
156
|
+
* <li>severity - the severity of this match. This can be one of the following:
|
|
157
|
+
* <ul>
|
|
158
|
+
* <li>suggestion - a suggestion of a better way to do things. The current way is
|
|
159
|
+
* not incorrect, but probably not optimal
|
|
160
|
+
* <li>warning - a problem that should be fixed, but which does not prevent
|
|
161
|
+
* your app from operating internationally. This is more severe than a suggestion.
|
|
162
|
+
* <li>error - a problem that must be fixed. This type of problem will prevent
|
|
163
|
+
* your app from operating properly internationally and could possibly even
|
|
164
|
+
* crash your app in some cases.
|
|
165
|
+
* </ul>
|
|
166
|
+
* <li>description - a description of the problem to display to the user. In order
|
|
167
|
+
* to make the ilib-lint output useful, this description should attempt to make the
|
|
168
|
+
* following things clear:
|
|
169
|
+
* <ul>
|
|
170
|
+
* <li>What part is wrong
|
|
171
|
+
* <li>Why it is wrong
|
|
172
|
+
* <li>Suggestions on how to fix it
|
|
173
|
+
* </ul>
|
|
174
|
+
* <li>lineNumber - the line number where the match occurred in multiline rules
|
|
175
|
+
* <li>highlight - the line where the problem occurred, highlighted with XML syntax
|
|
176
|
+
* (see below)
|
|
177
|
+
* </ul>
|
|
178
|
+
*
|
|
179
|
+
* For the `highlight` property, the line that has a problem is reproduced with
|
|
180
|
+
* XML tags around the problem part, if it is known. The tags are of the form
|
|
181
|
+
* &lt;eX&gt; where X is a digit starting with 0 and progressing to 9 for each
|
|
182
|
+
* subsequent problem. If the file type is XML already, the rest of the line will
|
|
183
|
+
* be XML-escaped first.<p>
|
|
184
|
+
*
|
|
185
|
+
* Example:<p>
|
|
186
|
+
*
|
|
187
|
+
* "const str = rb.getString(<e0>id</e0>);"<p>
|
|
188
|
+
*
|
|
189
|
+
* In this rule, `getString()` must be called with a static string in order for the
|
|
190
|
+
* loctool to be able to extract that string. The line above calls `getString()`
|
|
191
|
+
* with a variable named "id" as a parameter. The variable is highlighted with the
|
|
192
|
+
* e0 tag. Callers can then translate the open and close tags appropriately for
|
|
193
|
+
* the output device, such as ASCII escapes for a regular terminal, or HTML tags
|
|
194
|
+
* for a web-based device.
|
|
195
|
+
*
|
|
196
|
+
* @param {Object} options The options object as per the description above
|
|
197
|
+
* @returns {Object|Array.<Object>|undefined} an object describing the problem if the rule
|
|
198
|
+
* does match for this locale, or an array of such Objects if there are multiple
|
|
199
|
+
* problems with the same input, or undefined if the rule does not match
|
|
200
|
+
*/
|
|
201
|
+
match(options) {
|
|
202
|
+
throw new Error("Cannot call Rule.match() directly.");
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export default Rule;</code></pre>
|
|
207
|
+
</article>
|
|
208
|
+
</section>
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
</div>
|
|
216
|
+
|
|
217
|
+
<br class="clear">
|
|
218
|
+
|
|
219
|
+
<footer>
|
|
220
|
+
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.
|
|
221
|
+
</footer>
|
|
222
|
+
|
|
223
|
+
<script>prettyPrint();</script>
|
|
224
|
+
<script src="scripts/polyfill.js"></script>
|
|
225
|
+
<script src="scripts/linenumber.js"></script>
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
</body>
|
|
230
|
+
</html>
|