@discord/eslint-plugin-discord-intl 0.31.0 → 0.32.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/lib/native-validation.js +14 -8
- package/package.json +2 -2
package/lib/native-validation.js
CHANGED
|
@@ -13,7 +13,8 @@ const {
|
|
|
13
13
|
IntlMessagesDatabase,
|
|
14
14
|
IntlDatabaseInsertStrategy,
|
|
15
15
|
} = require('@discord/intl-message-database');
|
|
16
|
-
/** @
|
|
16
|
+
/** @typedef {{ sourceFileKey: string, validations: Record<string, IntlDiagnostic[]> }} FileValidations */
|
|
17
|
+
/** @type {Map<SourceCode, FileValidations>} */
|
|
17
18
|
const FILE_VALIDATIONS = new Map();
|
|
18
19
|
|
|
19
20
|
/** @type {Map<string, IntlMessagesDatabase>} */
|
|
@@ -50,7 +51,7 @@ function ensureInitialized(directory) {
|
|
|
50
51
|
* @param {SourceCode} sourceCode
|
|
51
52
|
* @param {string} fileName
|
|
52
53
|
* @param {string} content
|
|
53
|
-
* @return {
|
|
54
|
+
* @return {FileValidations}
|
|
54
55
|
*/
|
|
55
56
|
function processAndValidateNative(database, sourceCode, fileName, content) {
|
|
56
57
|
const fileKey = crypto.hash('sha1', content);
|
|
@@ -67,6 +68,10 @@ function processAndValidateNative(database, sourceCode, fileName, content) {
|
|
|
67
68
|
'en-US',
|
|
68
69
|
IntlDatabaseInsertStrategy.Update,
|
|
69
70
|
);
|
|
71
|
+
// The database interns file paths and may store a different spelling than the one we passed in
|
|
72
|
+
// (on Windows it normalizes the drive letter and separators). Every diagnostic it hands back is
|
|
73
|
+
// tagged with _its_ spelling, so match on this rather than on `processingFileName`.
|
|
74
|
+
const sourceFileKey = processResult.fileKey;
|
|
70
75
|
|
|
71
76
|
/** @type {Record<string, IntlDiagnostic[]>} */
|
|
72
77
|
const validations = {};
|
|
@@ -77,7 +82,7 @@ function processAndValidateNative(database, sourceCode, fileName, content) {
|
|
|
77
82
|
name: 'Processing::' + error.name,
|
|
78
83
|
description: error.message,
|
|
79
84
|
key: error.key ?? 'file',
|
|
80
|
-
file: error.file ??
|
|
85
|
+
file: error.file ?? sourceFileKey,
|
|
81
86
|
messageLine: error.line ?? 0,
|
|
82
87
|
messageCol: error.col ?? 0,
|
|
83
88
|
start: 0,
|
|
@@ -89,13 +94,14 @@ function processAndValidateNative(database, sourceCode, fileName, content) {
|
|
|
89
94
|
}
|
|
90
95
|
|
|
91
96
|
for (const diagnostic of database.validateMessages()) {
|
|
92
|
-
if (diagnostic.file ===
|
|
97
|
+
if (diagnostic.file === sourceFileKey) {
|
|
93
98
|
(validations[diagnostic.key] ??= []).push(diagnostic);
|
|
94
99
|
}
|
|
95
100
|
}
|
|
96
101
|
|
|
97
|
-
|
|
98
|
-
|
|
102
|
+
const result = { sourceFileKey, validations };
|
|
103
|
+
FILE_VALIDATIONS.set(sourceCode, result);
|
|
104
|
+
return result;
|
|
99
105
|
}
|
|
100
106
|
|
|
101
107
|
/**
|
|
@@ -111,7 +117,7 @@ function traverseAndReportMatchingNativeValidations(context, predicate) {
|
|
|
111
117
|
|
|
112
118
|
const projectDirectory = context.settings['intl']?.['projectDirectory'] ?? context.cwd;
|
|
113
119
|
const database = ensureInitialized(projectDirectory);
|
|
114
|
-
const validations = processAndValidateNative(
|
|
120
|
+
const { sourceFileKey, validations } = processAndValidateNative(
|
|
115
121
|
database,
|
|
116
122
|
context.sourceCode,
|
|
117
123
|
context.filename,
|
|
@@ -133,7 +139,7 @@ function traverseAndReportMatchingNativeValidations(context, predicate) {
|
|
|
133
139
|
// log the diagnostic to be able to investigate further when it happens.
|
|
134
140
|
const textLen = context.sourceCode.text.length;
|
|
135
141
|
if (
|
|
136
|
-
diagnostic.file !==
|
|
142
|
+
diagnostic.file !== sourceFileKey ||
|
|
137
143
|
messageOffset + diagnostic.start > textLen ||
|
|
138
144
|
messageOffset + diagnostic.end > textLen
|
|
139
145
|
) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discord/eslint-plugin-discord-intl",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"description": "ESLint plugin for validating and linting messages and translations using @discord/intl",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@typescript-eslint/scope-manager": "^8.8.1",
|
|
14
|
-
"@discord/intl-message-database": "0.
|
|
14
|
+
"@discord/intl-message-database": "0.32.0"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@types/eslint": "^8.56.12",
|