@discord/eslint-plugin-discord-intl 0.27.3 → 0.27.4
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 +45 -34
- package/lib/traverse.js +1 -1
- package/package.json +2 -2
package/lib/native-validation.js
CHANGED
|
@@ -4,30 +4,38 @@
|
|
|
4
4
|
/** @typedef {import('eslint').Rule.ReportDescriptorLocation} ReportDescriptorLocation */
|
|
5
5
|
/** @typedef {import('eslint').AST.SourceLocation} SourceLocation */
|
|
6
6
|
/** @typedef {import('eslint').SourceCode} SourceCode */
|
|
7
|
-
/** @typedef {import("@discord/intl-
|
|
7
|
+
/** @typedef {import("@discord/intl-message-database").IntlDiagnostic} IntlDiagnostic */
|
|
8
8
|
|
|
9
9
|
const crypto = require('node:crypto');
|
|
10
|
-
const
|
|
11
|
-
processDefinitionsFile,
|
|
12
|
-
database,
|
|
13
|
-
processAllMessagesFiles,
|
|
14
|
-
findAllMessagesFiles,
|
|
15
|
-
} = require('@discord/intl-loader-core');
|
|
10
|
+
const path = require('node:path');
|
|
16
11
|
const { traverseMessageDefinitions, isDefinitionsFile } = require('./traverse');
|
|
17
|
-
const
|
|
12
|
+
const {
|
|
13
|
+
IntlMessagesDatabase,
|
|
14
|
+
IntlDatabaseInsertStrategy,
|
|
15
|
+
} = require('@discord/intl-message-database');
|
|
18
16
|
/** @type {Map<SourceCode, Record<string, IntlDiagnostic[]>>} */
|
|
19
17
|
const FILE_VALIDATIONS = new Map();
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
/** @type {Map<string, IntlMessagesDatabase>} */
|
|
20
|
+
const PROJECT_DATABASE_MAP = new Map();
|
|
22
21
|
|
|
23
22
|
/**
|
|
24
23
|
* @param {string} directory
|
|
24
|
+
* @returns {IntlMessagesDatabase}
|
|
25
25
|
*/
|
|
26
26
|
function ensureInitialized(directory) {
|
|
27
|
-
|
|
27
|
+
const key = path.resolve(directory);
|
|
28
|
+
const existing = PROJECT_DATABASE_MAP.get(key);
|
|
29
|
+
if (existing != null) return existing;
|
|
30
|
+
|
|
31
|
+
const database = new IntlMessagesDatabase();
|
|
32
|
+
database.processAllMessagesFiles(
|
|
33
|
+
database.findAllMessagesFiles([directory], 'en-US'),
|
|
34
|
+
IntlDatabaseInsertStrategy.Create,
|
|
35
|
+
);
|
|
28
36
|
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
PROJECT_DATABASE_MAP.set(key, database);
|
|
38
|
+
return database;
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
/**
|
|
@@ -38,12 +46,13 @@ function ensureInitialized(directory) {
|
|
|
38
46
|
* validations, allowing them to be reused across multiple rules without wasting work validating
|
|
39
47
|
* the same messages multiple times.
|
|
40
48
|
*
|
|
49
|
+
* @param {IntlMessagesDatabase} database
|
|
41
50
|
* @param {SourceCode} sourceCode
|
|
42
51
|
* @param {string} fileName
|
|
43
52
|
* @param {string} content
|
|
44
53
|
* @return {Record<string, IntlDiagnostic[]>}
|
|
45
54
|
*/
|
|
46
|
-
function processAndValidateNative(sourceCode, fileName, content) {
|
|
55
|
+
function processAndValidateNative(database, sourceCode, fileName, content) {
|
|
47
56
|
const fileKey = crypto.hash('sha1', content);
|
|
48
57
|
const existing = FILE_VALIDATIONS.get(sourceCode);
|
|
49
58
|
if (existing != null) return existing;
|
|
@@ -52,30 +61,31 @@ function processAndValidateNative(sourceCode, fileName, content) {
|
|
|
52
61
|
// native database that this is a JS message definition _somehow_, so we'll make a random
|
|
53
62
|
// name that should be relatively unique.
|
|
54
63
|
const processingFileName = fileName === '<input>' ? `${fileKey}.messages.js` : fileName;
|
|
55
|
-
const processResult =
|
|
56
|
-
|
|
57
|
-
|
|
64
|
+
const processResult = database.processDefinitionsFileContent(
|
|
65
|
+
processingFileName,
|
|
66
|
+
content,
|
|
67
|
+
'en-US',
|
|
68
|
+
IntlDatabaseInsertStrategy.Update,
|
|
69
|
+
);
|
|
58
70
|
|
|
59
71
|
/** @type {Record<string, IntlDiagnostic[]>} */
|
|
60
72
|
const validations = {};
|
|
61
73
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
});
|
|
78
|
-
}
|
|
74
|
+
for (const error of processResult.errors) {
|
|
75
|
+
const key = error.key ?? 'file';
|
|
76
|
+
(validations[key] ??= []).push({
|
|
77
|
+
name: 'Processing::' + error.name,
|
|
78
|
+
description: error.message,
|
|
79
|
+
key: error.key ?? 'file',
|
|
80
|
+
file: error.file ?? processingFileName,
|
|
81
|
+
messageLine: error.line ?? 0,
|
|
82
|
+
messageCol: error.col ?? 0,
|
|
83
|
+
start: 0,
|
|
84
|
+
end: 2,
|
|
85
|
+
locale: error.locale ?? 'definition',
|
|
86
|
+
category: 'correctness',
|
|
87
|
+
fixes: [],
|
|
88
|
+
});
|
|
79
89
|
}
|
|
80
90
|
|
|
81
91
|
for (const diagnostic of database.validateMessages()) {
|
|
@@ -100,8 +110,9 @@ function traverseAndReportMatchingNativeValidations(context, predicate) {
|
|
|
100
110
|
if (!isDefinitionsFile(context.filename, context.sourceCode.text)) return {};
|
|
101
111
|
|
|
102
112
|
const projectDirectory = context.settings['intl']?.['projectDirectory'] ?? context.cwd;
|
|
103
|
-
ensureInitialized(projectDirectory);
|
|
113
|
+
const database = ensureInitialized(projectDirectory);
|
|
104
114
|
const validations = processAndValidateNative(
|
|
115
|
+
database,
|
|
105
116
|
context.sourceCode,
|
|
106
117
|
context.filename,
|
|
107
118
|
context.sourceCode.text,
|
package/lib/traverse.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { isMessageDefinitionsFile } = require('@discord/intl-
|
|
1
|
+
const { isMessageDefinitionsFile } = require('@discord/intl-message-database');
|
|
2
2
|
|
|
3
3
|
/** @typedef {import('eslint').Rule.NodeParentExtension} NodeParentExtension */
|
|
4
4
|
/** @typedef {import('eslint').SourceCode} SourceCode */
|
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.4",
|
|
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-
|
|
14
|
+
"@discord/intl-message-database": "0.27.4"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@types/eslint": "^8.56.12",
|