@discord/eslint-plugin-discord-intl 0.27.2 → 0.27.3
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 +22 -1
- package/package.json +2 -2
package/lib/native-validation.js
CHANGED
|
@@ -14,6 +14,7 @@ const {
|
|
|
14
14
|
findAllMessagesFiles,
|
|
15
15
|
} = require('@discord/intl-loader-core');
|
|
16
16
|
const { traverseMessageDefinitions, isDefinitionsFile } = require('./traverse');
|
|
17
|
+
const diagnostics_channel = require('node:diagnostics_channel');
|
|
17
18
|
/** @type {Map<SourceCode, Record<string, IntlDiagnostic[]>>} */
|
|
18
19
|
const FILE_VALIDATIONS = new Map();
|
|
19
20
|
|
|
@@ -97,7 +98,9 @@ function processAndValidateNative(sourceCode, fileName, content) {
|
|
|
97
98
|
*/
|
|
98
99
|
function traverseAndReportMatchingNativeValidations(context, predicate) {
|
|
99
100
|
if (!isDefinitionsFile(context.filename, context.sourceCode.text)) return {};
|
|
100
|
-
|
|
101
|
+
|
|
102
|
+
const projectDirectory = context.settings['intl']?.['projectDirectory'] ?? context.cwd;
|
|
103
|
+
ensureInitialized(projectDirectory);
|
|
101
104
|
const validations = processAndValidateNative(
|
|
102
105
|
context.sourceCode,
|
|
103
106
|
context.filename,
|
|
@@ -114,6 +117,24 @@ function traverseAndReportMatchingNativeValidations(context, predicate) {
|
|
|
114
117
|
column: diagnostic.messageCol,
|
|
115
118
|
});
|
|
116
119
|
|
|
120
|
+
// Sometimes we get a diagnostic pointing to a different file than the
|
|
121
|
+
// current source code. Not totally sure why for now, so lets just noisily
|
|
122
|
+
// log the diagnostic to be able to investigate further when it happens.
|
|
123
|
+
const textLen = context.sourceCode.text.length;
|
|
124
|
+
if (
|
|
125
|
+
diagnostic.file !== context.physicalFilename ||
|
|
126
|
+
messageOffset + diagnostic.start > textLen ||
|
|
127
|
+
messageOffset + diagnostic.end > textLen
|
|
128
|
+
) {
|
|
129
|
+
console.error('Invalid diagnostic span from intl vs eslint:');
|
|
130
|
+
console.log('ESLint source filename:', context.filename);
|
|
131
|
+
console.log(diagnostic);
|
|
132
|
+
return {
|
|
133
|
+
start: context.sourceCode.getLocFromIndex(1),
|
|
134
|
+
end: context.sourceCode.getLocFromIndex(1),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
117
138
|
return {
|
|
118
139
|
start: context.sourceCode.getLocFromIndex(messageOffset + diagnostic.start),
|
|
119
140
|
end: context.sourceCode.getLocFromIndex(messageOffset + diagnostic.end),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discord/eslint-plugin-discord-intl",
|
|
3
|
-
"version": "0.27.
|
|
3
|
+
"version": "0.27.3",
|
|
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-loader-core": "0.27.
|
|
14
|
+
"@discord/intl-loader-core": "0.27.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@types/eslint": "^8.56.12",
|