ilib-lint 2.21.4 → 2.21.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ilib-lint",
3
- "version": "2.21.4",
3
+ "version": "2.21.5",
4
4
  "type": "module",
5
5
  "main": "./src/index.js",
6
6
  "module": "./src/index.js",
@@ -77,15 +77,15 @@
77
77
  "options-parser": "^0.4.0",
78
78
  "xml-js": "^1.6.11",
79
79
  "ilib-xliff-webos": "^1.0.11",
80
- "ilib-casemapper": "^1.0.2",
81
80
  "ilib-common": "^1.1.7",
81
+ "ilib-casemapper": "^1.0.2",
82
82
  "ilib-ctype": "^1.3.0",
83
83
  "ilib-lint-common": "^3.7.0",
84
84
  "ilib-locale": "^1.4.0",
85
85
  "ilib-localematcher": "^1.3.4",
86
86
  "ilib-scriptinfo": "^1.0.0",
87
- "ilib-tools-common": "^1.22.0",
88
- "ilib-xliff": "^1.4.1"
87
+ "ilib-xliff": "^1.4.1",
88
+ "ilib-tools-common": "^1.22.0"
89
89
  },
90
90
  "scripts": {
91
91
  "coverage": "LANG=en_US.UTF8 node --trace-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
@@ -102,9 +102,11 @@ const punctuationMap = {
102
102
 
103
103
  /**
104
104
  * @ignore
105
- * @typedef {{minimumLength?: number}} ResourceSentenceEndingFixedOptions
105
+ * @typedef {{minimumLength?: number, exceptions?: string[]}} ResourceSentenceEndingFixedOptions
106
106
  * @property {number} [minimumLength=10] - Minimum length of source string before the rule is applied.
107
107
  * Strings shorter than this length will be skipped (useful for avoiding false positives on abbreviations).
108
+ * @property {string[]} [exceptions] - Array of source strings to skip checking for ALL locales.
109
+ * Useful for handling special cases that should be globally excluded from sentence-ending punctuation checks.
108
110
  */
109
111
 
110
112
  /**
@@ -120,7 +122,7 @@ class ResourceSentenceEnding extends ResourceRule {
120
122
  /**
121
123
  * Constructs a new ResourceSentenceEnding rule instance.
122
124
  *
123
- * @param {ResourceSentenceEndingOptions} [options] - Configuration options for the rule
125
+ * @param {{ param?: ResourceSentenceEndingOptions, sourceLocale?: string, getLogger?: Function }} [options] - Configuration options for the rule
124
126
  *
125
127
  * @example
126
128
  * // Basic usage with default settings
@@ -181,9 +183,16 @@ class ResourceSentenceEnding extends ResourceRule {
181
183
  // Initialize minimum length configuration
182
184
  this.minimumLength = Math.max(0, param?.minimumLength ?? 10);
183
185
 
186
+ // Initialize global exceptions (apply to all locales), deduplicated via Set
187
+ this.globalExceptions = new Set(
188
+ Array.isArray(param?.exceptions)
189
+ ? param.exceptions.map((/** @type {string} */ e) => e.toLowerCase().trim())
190
+ : []
191
+ );
192
+
184
193
  // Initialize custom punctuation mappings from configuration
185
194
  this.customPunctuationMap = {};
186
- // Initialize exception lists from configuration
195
+ // Initialize locale-specific exception lists from configuration
187
196
  this.exceptionsMap = {};
188
197
 
189
198
  if (param && typeof param === 'object' && !Array.isArray(param)) {
@@ -211,9 +220,11 @@ class ResourceSentenceEnding extends ResourceRule {
211
220
  ...punctuationMappings
212
221
  };
213
222
 
214
- // Store exceptions separately
223
+ // Store exceptions as a Set to deduplicate
215
224
  if (exceptions && Array.isArray(exceptions)) {
216
- this.exceptionsMap[language] = exceptions;
225
+ this.exceptionsMap[language] = new Set(
226
+ exceptions.map((/** @type {string} */ e) => e.toLowerCase().trim())
227
+ );
217
228
  }
218
229
  }
219
230
  }
@@ -982,12 +993,17 @@ class ResourceSentenceEnding extends ResourceRule {
982
993
  }
983
994
  }
984
995
 
985
- // Exception 3: Check if source is in exception list
996
+ const normalizedSource = source.toLowerCase().trim();
997
+
998
+ // Exception 3: Check if source is in global exception list (all locales)
999
+ if (this.globalExceptions.has(normalizedSource)) {
1000
+ return undefined;
1001
+ }
1002
+
1003
+ // Exception 4: Check if source is in locale-specific exception list
986
1004
  const exceptions = this.exceptionsMap[targetLanguage];
987
- if (exceptions) {
988
- if (exceptions.some(exception => exception.toLowerCase().trim() === source.toLowerCase().trim())) {
989
- return undefined;
990
- }
1005
+ if (exceptions?.has(normalizedSource)) {
1006
+ return undefined;
991
1007
  }
992
1008
 
993
1009
  const optionalPunctuationLanguages = ['th', 'lo', 'my', 'km', 'vi', 'id', 'ms', 'tl', 'jv', 'su'];