@generaltranslation/react-core-linter 0.0.0-alpha.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.md +105 -0
- package/README.md +6 -0
- package/dist/configs/recommended.d.ts +7 -0
- package/dist/configs/recommended.d.ts.map +1 -0
- package/dist/configs/recommended.js +20 -0
- package/dist/configs/recommended.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/rules/static-jsx/ScopeStack.d.ts +16 -0
- package/dist/rules/static-jsx/ScopeStack.d.ts.map +1 -0
- package/dist/rules/static-jsx/ScopeStack.js +35 -0
- package/dist/rules/static-jsx/ScopeStack.js.map +1 -0
- package/dist/rules/static-jsx/index.d.ts +5 -0
- package/dist/rules/static-jsx/index.d.ts.map +1 -0
- package/dist/rules/static-jsx/index.js +160 -0
- package/dist/rules/static-jsx/index.js.map +1 -0
- package/dist/rules/static-string/index.d.ts +5 -0
- package/dist/rules/static-string/index.d.ts.map +1 -0
- package/dist/rules/static-string/index.js +115 -0
- package/dist/rules/static-string/index.js.map +1 -0
- package/dist/utils/branching-utils.d.ts +9 -0
- package/dist/utils/branching-utils.d.ts.map +1 -0
- package/dist/utils/branching-utils.js +22 -0
- package/dist/utils/branching-utils.js.map +1 -0
- package/dist/utils/constants.d.ts +27 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +63 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/isGTFunction.d.ts +23 -0
- package/dist/utils/isGTFunction.d.ts.map +1 -0
- package/dist/utils/isGTFunction.js +179 -0
- package/dist/utils/isGTFunction.js.map +1 -0
- package/package.json +81 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-ALv2
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2025 General Translation, Inc.
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recommended.d.ts","sourceRoot":"","sources":["../../src/configs/recommended.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,iBAAS,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAc/D;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recommended ESLint configuration for React Core
|
|
3
|
+
*/
|
|
4
|
+
function injectRecommended(plugin) {
|
|
5
|
+
return {
|
|
6
|
+
...plugin,
|
|
7
|
+
configs: {
|
|
8
|
+
...plugin.configs,
|
|
9
|
+
recommended: {
|
|
10
|
+
plugins: { '@generaltranslation/react-core-linter': plugin },
|
|
11
|
+
rules: {
|
|
12
|
+
'@generaltranslation/react-core-linter/static-jsx': 'error',
|
|
13
|
+
'@generaltranslation/react-core-linter/static-string': 'error',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export { injectRecommended };
|
|
20
|
+
//# sourceMappingURL=recommended.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recommended.js","sourceRoot":"","sources":["../../src/configs/recommended.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,SAAS,iBAAiB,CAAC,MAAqB;IAC9C,OAAO;QACL,GAAG,MAAM;QACT,OAAO,EAAE;YACP,GAAG,MAAM,CAAC,OAAO;YACjB,WAAW,EAAE;gBACX,OAAO,EAAE,EAAE,uCAAuC,EAAE,MAAM,EAAE;gBAC5D,KAAK,EAAE;oBACL,kDAAkD,EAAE,OAAO;oBAC3D,qDAAqD,EAAE,OAAO;iBAC/D;aACF;SACF;KACF,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Core ESLint Plugin
|
|
3
|
+
*
|
|
4
|
+
* Provides ESLint rules for General Translation React Core integration.
|
|
5
|
+
* This plugin helps ensure correct usage of React Core i18n components
|
|
6
|
+
* and translation patterns.
|
|
7
|
+
*/
|
|
8
|
+
import type { ESLint } from 'eslint';
|
|
9
|
+
declare const plugin: ESLint.Plugin;
|
|
10
|
+
export default plugin;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAQ,MAAM,QAAQ,CAAC;AAK3C,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,MAkBpB,CAAC;AAeF,eAAe,MAAM,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Core ESLint Plugin
|
|
3
|
+
*
|
|
4
|
+
* Provides ESLint rules for General Translation React Core integration.
|
|
5
|
+
* This plugin helps ensure correct usage of React Core i18n components
|
|
6
|
+
* and translation patterns.
|
|
7
|
+
*/
|
|
8
|
+
import { staticJsx } from './rules/static-jsx/index.js';
|
|
9
|
+
import { staticString } from './rules/static-string/index.js';
|
|
10
|
+
const plugin = {
|
|
11
|
+
meta: {
|
|
12
|
+
name: '@generaltranslation/react-core-linter',
|
|
13
|
+
version: '0.0.0',
|
|
14
|
+
},
|
|
15
|
+
rules: {
|
|
16
|
+
'static-jsx': staticJsx,
|
|
17
|
+
'static-string': staticString,
|
|
18
|
+
},
|
|
19
|
+
configs: {
|
|
20
|
+
recommended: {
|
|
21
|
+
plugins: ['@generaltranslation/react-core-linter'],
|
|
22
|
+
rules: {
|
|
23
|
+
'@generaltranslation/react-core-linter/static-jsx': 'error',
|
|
24
|
+
'@generaltranslation/react-core-linter/static-string': 'error',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
plugin.configs = {
|
|
30
|
+
recommended: {
|
|
31
|
+
plugins: { '@generaltranslation/react-core-linter': plugin },
|
|
32
|
+
rules: {
|
|
33
|
+
'@generaltranslation/react-core-linter/static-jsx': 'error',
|
|
34
|
+
'@generaltranslation/react-core-linter/static-string': 'error',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
// // Add the recommended config
|
|
39
|
+
// injectRecommended(plugin);
|
|
40
|
+
export default plugin;
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAG9D,MAAM,MAAM,GAAkB;IAC5B,IAAI,EAAE;QACJ,IAAI,EAAE,uCAAuC;QAC7C,OAAO,EAAE,OAAO;KACjB;IACD,KAAK,EAAE;QACL,YAAY,EAAE,SAAuC;QACrD,eAAe,EAAE,YAA0C;KAC5D;IACD,OAAO,EAAE;QACP,WAAW,EAAE;YACX,OAAO,EAAE,CAAC,uCAAuC,CAAC;YAClD,KAAK,EAAE;gBACL,kDAAkD,EAAE,OAAO;gBAC3D,qDAAqD,EAAE,OAAO;aAC/D;SACF;KACF;CACF,CAAC;AAEF,MAAM,CAAC,OAAO,GAAG;IACf,WAAW,EAAE;QACX,OAAO,EAAE,EAAE,uCAAuC,EAAE,MAAM,EAAE;QAC5D,KAAK,EAAE;YACL,kDAAkD,EAAE,OAAO;YAC3D,qDAAqD,EAAE,OAAO;SAC/D;KACF;CACF,CAAC;AAEF,gCAAgC;AAChC,6BAA6B;AAE7B,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type Scope = 'no-T' | 'T' | 'Branch' | 'Plural' | 'Branching-Attribute';
|
|
2
|
+
/**
|
|
3
|
+
* Utility for tracking scope in JSX tree
|
|
4
|
+
*/
|
|
5
|
+
export declare class ScopeStack {
|
|
6
|
+
private stack;
|
|
7
|
+
constructor();
|
|
8
|
+
push(scope: Scope): void;
|
|
9
|
+
pop(): void;
|
|
10
|
+
inTranslatableContent(): boolean;
|
|
11
|
+
inBranchingComponent(): boolean;
|
|
12
|
+
inBranchingAttribute(): boolean;
|
|
13
|
+
inBranchT(): boolean;
|
|
14
|
+
getScope(): Scope;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=ScopeStack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScopeStack.d.ts","sourceRoot":"","sources":["../../../src/rules/static-jsx/ScopeStack.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GACb,MAAM,GACN,GAAG,GACH,QAAQ,GACR,QAAQ,GACR,qBAAqB,CAAC;AAE1B;;GAEG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,KAAK,CAAe;;IAM5B,IAAI,CAAC,KAAK,EAAE,KAAK;IAIjB,GAAG;IAIH,qBAAqB,IAAI,OAAO;IAIhC,oBAAoB,IAAI,OAAO;IAI/B,oBAAoB,IAAI,OAAO;IAG/B,SAAS,IAAI,OAAO;IAOpB,QAAQ;CAGT"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility for tracking scope in JSX tree
|
|
3
|
+
*/
|
|
4
|
+
export class ScopeStack {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.stack = [];
|
|
7
|
+
this.stack.push('no-T');
|
|
8
|
+
}
|
|
9
|
+
push(scope) {
|
|
10
|
+
this.stack.push(scope);
|
|
11
|
+
}
|
|
12
|
+
pop() {
|
|
13
|
+
this.stack.pop();
|
|
14
|
+
}
|
|
15
|
+
inTranslatableContent() {
|
|
16
|
+
const scope = this.stack[this.stack.length - 1];
|
|
17
|
+
return scope === 'T';
|
|
18
|
+
}
|
|
19
|
+
inBranchingComponent() {
|
|
20
|
+
const scope = this.stack[this.stack.length - 1];
|
|
21
|
+
return scope === 'Branch' || scope === 'Plural';
|
|
22
|
+
}
|
|
23
|
+
inBranchingAttribute() {
|
|
24
|
+
return this.stack[this.stack.length - 1] === 'Branching-Attribute';
|
|
25
|
+
}
|
|
26
|
+
inBranchT() {
|
|
27
|
+
return (this.stack.length >= 2 &&
|
|
28
|
+
this.stack[this.stack.length - 1] === 'T' &&
|
|
29
|
+
this.stack[this.stack.length - 2] === 'Branching-Attribute');
|
|
30
|
+
}
|
|
31
|
+
getScope() {
|
|
32
|
+
return this.stack[this.stack.length - 1];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=ScopeStack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScopeStack.js","sourceRoot":"","sources":["../../../src/rules/static-jsx/ScopeStack.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,OAAO,UAAU;IAGrB;QAFQ,UAAK,GAAY,EAAE,CAAC;QAG1B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1B,CAAC;IAED,IAAI,CAAC,KAAY;QACf,IAAI,C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1,160 @@
|
|
|
1
|
+
import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import { ALLOWED_BRANCH_ATTRIBUTE_JSX_EXPRESSIONS, ALLOWED_JSX_EXPRESSIONS, GT_LIBRARIES, RULE_URL, } from '../../utils/constants.js';
|
|
3
|
+
import { isBranchComponent, isBranchingComponent, isStaticComponent, isTComponent, isVariableComponent, } from '../../utils/isGTFunction.js';
|
|
4
|
+
import { isContentBranch } from '../../utils/branching-utils.js';
|
|
5
|
+
import { ScopeStack } from './ScopeStack.js';
|
|
6
|
+
/**
|
|
7
|
+
* Creates a fixer that wraps a JSX expression container in a <Var> component
|
|
8
|
+
*/
|
|
9
|
+
function createVarWrapperFix(context, fixer, node) {
|
|
10
|
+
// Get the source code of the expression container
|
|
11
|
+
const sourceCode = context.sourceCode.getText(node);
|
|
12
|
+
// Wrap in <Var> component
|
|
13
|
+
const fixedCode = `<Var>${sourceCode}</Var>`;
|
|
14
|
+
return fixer.replaceText(node, fixedCode);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Static JSX applies to children of the <T> component
|
|
18
|
+
*/
|
|
19
|
+
const createRule = ESLintUtils.RuleCreator((name) => `${RULE_URL}${name}`);
|
|
20
|
+
export const staticJsx = createRule({
|
|
21
|
+
name: 'static-jsx',
|
|
22
|
+
meta: {
|
|
23
|
+
type: 'problem',
|
|
24
|
+
docs: {
|
|
25
|
+
description: 'The <T> component must only have static children.',
|
|
26
|
+
},
|
|
27
|
+
fixable: 'code',
|
|
28
|
+
schema: [
|
|
29
|
+
{
|
|
30
|
+
type: 'object',
|
|
31
|
+
properties: {
|
|
32
|
+
libs: {
|
|
33
|
+
type: 'array',
|
|
34
|
+
items: {
|
|
35
|
+
type: 'string',
|
|
36
|
+
},
|
|
37
|
+
description: 'List of library modules to check for translation components',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
additionalProperties: false,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
hasSuggestions: false,
|
|
44
|
+
messages: {
|
|
45
|
+
dynamicContent: 'All dynamic content must be wrapped in a variable component (<Var>, <DateTime>, <Num>, or <Currency>).',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
defaultOptions: [{ libs: GT_LIBRARIES }],
|
|
49
|
+
create(context, [options]) {
|
|
50
|
+
const { libs = GT_LIBRARIES } = options;
|
|
51
|
+
// Track the T component stack
|
|
52
|
+
const scopeStack = new ScopeStack();
|
|
53
|
+
return {
|
|
54
|
+
/**
|
|
55
|
+
* Flag dynamic content
|
|
56
|
+
* When we are inside of a branching attribute, mark it as Branch-T
|
|
57
|
+
*/
|
|
58
|
+
JSXExpressionContainer(node) {
|
|
59
|
+
if (!node.expression)
|
|
60
|
+
return;
|
|
61
|
+
// Handle T component and branching attribute cases
|
|
62
|
+
if (scopeStack.inTranslatableContent()) {
|
|
63
|
+
if (!ALLOWED_JSX_EXPRESSIONS.includes(node.expression.type)) {
|
|
64
|
+
return context.report({
|
|
65
|
+
node,
|
|
66
|
+
messageId: 'dynamicContent',
|
|
67
|
+
fix(fixer) {
|
|
68
|
+
return createVarWrapperFix(context, fixer, node);
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if (scopeStack.inBranchingAttribute()) {
|
|
74
|
+
// Translate as normal
|
|
75
|
+
scopeStack.push('T');
|
|
76
|
+
// Check errors
|
|
77
|
+
if (!ALLOWED_BRANCH_ATTRIBUTE_JSX_EXPRESSIONS.includes(node.expression.type)) {
|
|
78
|
+
return context.report({
|
|
79
|
+
node,
|
|
80
|
+
messageId: 'dynamicContent',
|
|
81
|
+
fix(fixer) {
|
|
82
|
+
return createVarWrapperFix(context, fixer, node);
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
'JSXExpressionContainer:exit'(node) {
|
|
89
|
+
if (!node.expression || !scopeStack.inBranchT())
|
|
90
|
+
return;
|
|
91
|
+
scopeStack.pop();
|
|
92
|
+
},
|
|
93
|
+
/**
|
|
94
|
+
* Flag the entrance/exit of a T component
|
|
95
|
+
*/
|
|
96
|
+
JSXElement(node) {
|
|
97
|
+
// Filter out non-T components
|
|
98
|
+
if (isTComponent({ context, node: node.openingElement, libs }))
|
|
99
|
+
scopeStack.push('T');
|
|
100
|
+
else if (isVariableComponent({ context, node: node.openingElement, libs }))
|
|
101
|
+
scopeStack.push('no-T');
|
|
102
|
+
else if (isStaticComponent({ context, node: node.openingElement, libs }))
|
|
103
|
+
scopeStack.push('no-T');
|
|
104
|
+
},
|
|
105
|
+
'JSXElement:exit'(node) {
|
|
106
|
+
if (isTComponent({ context, node: node.openingElement, libs }) ||
|
|
107
|
+
isVariableComponent({ context, node: node.openingElement, libs }) ||
|
|
108
|
+
isStaticComponent({ context, node: node.openingElement, libs })) {
|
|
109
|
+
scopeStack.pop();
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
/**
|
|
113
|
+
* JSXOpeningElement, JSXOpeningElement:exit handle ignoring arguments
|
|
114
|
+
*/
|
|
115
|
+
JSXOpeningElement(node) {
|
|
116
|
+
if (scopeStack.inTranslatableContent() &&
|
|
117
|
+
isBranchingComponent({ context, node, libs })) {
|
|
118
|
+
if (isBranchComponent({ context, node, libs })) {
|
|
119
|
+
scopeStack.push('Branch');
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
scopeStack.push('Plural');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
scopeStack.push('no-T');
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
'JSXOpeningElement:exit'() {
|
|
130
|
+
scopeStack.pop();
|
|
131
|
+
},
|
|
132
|
+
/**
|
|
133
|
+
* JSXAttribute for branch/plural children
|
|
134
|
+
* TODO: disallow spreads, (unless we know that they somehow only contain "branch" or "n" properties)
|
|
135
|
+
*/
|
|
136
|
+
JSXAttribute(node) {
|
|
137
|
+
// Filter out non-branching attributes, or non-expression containers
|
|
138
|
+
if (!scopeStack.inBranchingComponent() ||
|
|
139
|
+
node.value?.type !== TSESTree.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
// Filter out branching properties, or non-options (null, literals, etc.)
|
|
143
|
+
if (!isContentBranch({ tScope: scopeStack.getScope(), node }))
|
|
144
|
+
return;
|
|
145
|
+
scopeStack.push('Branching-Attribute');
|
|
146
|
+
},
|
|
147
|
+
'JSXAttribute:exit'(node) {
|
|
148
|
+
if (!scopeStack.inBranchingAttribute() ||
|
|
149
|
+
node.value?.type !== TSESTree.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
// Filter out branching properties, or non-options (null, literals, etc.)
|
|
153
|
+
if (!isContentBranch({ tScope: scopeStack.getScope(), node }))
|
|
154
|
+
return;
|
|
155
|
+
scopeStack.pop();
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/rules/static-jsx/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAKjE,OAAO,EACL,wCAAwC,EACxC,uBAAuB,EACvB,YAAY,EACZ,QAAQ,GACT,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,GACpB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;GAEG;AACH,SAAS,mBAAmB,CAC1B,OAA8B,EAC9B,KAAgB,EAChB,I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,CAAC,IAA2B;gBACtC,oEAAoE;gBACpE,IACE,CAAC,UAAU,CAAC,oBAAoB,EAAE;oBAClC,IAAI,CAAC,KAAK,EAAE,IAAI,KAAK,QAAQ,CAAC,cAAc,CAAC,sBAAsB,EACnE,CAAC;oBACD,OAAO;gBACT,CAAC;gBAED,yEAAyE;gBACzE,IAAI,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC;oBAAE,OAAO;gBACtE,UAAU,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;YACzC,CAAC;YACD,mBAAmB,CAAC,IAA2B;gBAC7C,IACE,CAAC,UAAU,CAAC,oBAAoB,EAAE;oBAClC,IAAI,CAAC,KAAK,EAAE,IAAI,KAAK,QAAQ,CAAC,cAAc,CAAC,sBAAsB,EACnE,CAAC;oBACD,OAAO;gBACT,CAAC;gBAED,yEAAyE;gBACzE,IAAI,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC;oBAAE,OAAO;gBACtE,UAAU,CAAC,GAAG,EAAE,CAAC;YACnB,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
export declare const staticString: ESLintUtils.RuleModule<"staticStringRequired" | "variableInterpolationRequired" | "missingVariableInInterpolation" | "sugarVariableMustBeStatic", [{
|
|
3
|
+
libs: string[];
|
|
4
|
+
}], unknown, ESLintUtils.RuleListener>;
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/rules/static-string/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAY,MAAM,0BAA0B,CAAC;AAwBjE,eAAO,MAAM,YAAY;;sCAkHvB,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import { GT_LIBRARIES, RULE_URL } from '../../utils/constants.js';
|
|
3
|
+
import { isDeclareStaticFunction, isGTCallbackFunction, isMsgFunction, } from '../../utils/isGTFunction.js';
|
|
4
|
+
/**
|
|
5
|
+
* Static string rule for translation components
|
|
6
|
+
*/
|
|
7
|
+
const createRule = ESLintUtils.RuleCreator((name) => `${RULE_URL}${name}`);
|
|
8
|
+
function isStaticString(node) {
|
|
9
|
+
switch (node.type) {
|
|
10
|
+
case TSESTree.AST_NODE_TYPES.Literal:
|
|
11
|
+
return typeof node.value === 'string';
|
|
12
|
+
case TSESTree.AST_NODE_TYPES.TemplateLiteral:
|
|
13
|
+
return node.expressions.length === 0;
|
|
14
|
+
default:
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export const staticString = createRule({
|
|
19
|
+
name: 'static-string',
|
|
20
|
+
meta: {
|
|
21
|
+
type: 'problem',
|
|
22
|
+
docs: {
|
|
23
|
+
description: 'Enforce static string usage in translation components.',
|
|
24
|
+
},
|
|
25
|
+
fixable: 'code',
|
|
26
|
+
schema: [
|
|
27
|
+
{
|
|
28
|
+
type: 'object',
|
|
29
|
+
properties: {
|
|
30
|
+
libs: {
|
|
31
|
+
type: 'array',
|
|
32
|
+
items: {
|
|
33
|
+
type: 'string',
|
|
34
|
+
},
|
|
35
|
+
description: 'List of library modules to check for translation components',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
additionalProperties: false,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
hasSuggestions: false,
|
|
42
|
+
messages: {
|
|
43
|
+
// generic error message (no fix)
|
|
44
|
+
staticStringRequired: 'Registration functions can only accept static strings. For example: msg("This is a static string!").',
|
|
45
|
+
// msg(`Hello, ${name}!`) TODO: autofix
|
|
46
|
+
variableInterpolationRequired: 'Dynamically constructed strings are not allowed. Use ICU-style variable interpolation instead (e.g. gt("Hello {name}!"), { name: value }).',
|
|
47
|
+
// TODO: missing a variable in interpolation (gt() only) (no fix)
|
|
48
|
+
missingVariableInInterpolation: 'Missing a variable in interpolation. Any variable supplied to the ICU-string, must be provided as a key in the options object.',
|
|
49
|
+
// TODO: any sugar variables must be static (no fix)
|
|
50
|
+
sugarVariableMustBeStatic: 'Sugar variables must be static strings. For example: gt("Hello!", { $context: "A greeting" }).',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
defaultOptions: [{ libs: GT_LIBRARIES }],
|
|
54
|
+
create(context, [options]) {
|
|
55
|
+
const { libs = GT_LIBRARIES } = options;
|
|
56
|
+
return {
|
|
57
|
+
/**
|
|
58
|
+
* Handle function calls
|
|
59
|
+
*/
|
|
60
|
+
CallExpression(node) {
|
|
61
|
+
if (!isMsgFunction({ context, node, libs }) &&
|
|
62
|
+
!isGTCallbackFunction({ context, node, libs })) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
// Ignore if there is no first argument
|
|
66
|
+
if (node.arguments.length === 0)
|
|
67
|
+
return;
|
|
68
|
+
// Disallow spread elements (no fix)
|
|
69
|
+
const firstArgument = node.arguments[0];
|
|
70
|
+
if (firstArgument.type === TSESTree.AST_NODE_TYPES.SpreadElement) {
|
|
71
|
+
return context.report({
|
|
72
|
+
node: firstArgument,
|
|
73
|
+
messageId: 'variableInterpolationRequired',
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
// Validate gt()'s params
|
|
77
|
+
validateGTInvocation(firstArgument);
|
|
78
|
+
/**
|
|
79
|
+
* Helper function to validate gt()'s params
|
|
80
|
+
*/
|
|
81
|
+
function validateGTInvocation(expression) {
|
|
82
|
+
// Static string is okay
|
|
83
|
+
if (isStaticString(expression))
|
|
84
|
+
return;
|
|
85
|
+
// declareStatic() is okay
|
|
86
|
+
if (expression.type === TSESTree.AST_NODE_TYPES.CallExpression &&
|
|
87
|
+
isDeclareStaticFunction({ context, node: expression, libs })) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
// Validate binary expressions: "A" + declareStatic(??) + `C`
|
|
91
|
+
if (expression.type === TSESTree.AST_NODE_TYPES.BinaryExpression &&
|
|
92
|
+
expression.operator === '+') {
|
|
93
|
+
validateGTInvocation(expression.left);
|
|
94
|
+
validateGTInvocation(expression.right);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
// Interpolation: `Hello ${name}!`
|
|
98
|
+
if (expression.type === TSESTree.AST_NODE_TYPES.TemplateLiteral) {
|
|
99
|
+
// TODO: keep track of nodes to interpolate
|
|
100
|
+
return context.report({
|
|
101
|
+
node: expression,
|
|
102
|
+
messageId: 'variableInterpolationRequired',
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
// Generic error message
|
|
106
|
+
return context.report({
|
|
107
|
+
node: expression,
|
|
108
|
+
messageId: 'staticStringRequired',
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/rules/static-string/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,aAAa,GACd,MAAM,6BAA6B,CAAC;AAErC;;GAEG;AACH,MAAM,UAAU,GAAG,WAAW,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,QAAQ,GAAG,IAAI,EAAE,CAAC,CAAC;AAE3E,SAAS,cAAc,CAAC,IAAyB;IAC/C,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;Q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M,CAAC;4BACpB,IAAI,EAAE,UAAU;4BAChB,SAAS,EAAE,+BAA+B;yBAC3C,CAAC,CAAC;oBACL,CAAC;oBAED,wBAAwB;oBACxB,OAAO,OAAO,CAAC,MAAM,CAAC;wBACpB,IAAI,EAAE,UAAU;wBAChB,SAAS,EAAE,sBAAsB;qBAClC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
/**
|
|
3
|
+
* Returns true if the given branch is a content branch
|
|
4
|
+
*/
|
|
5
|
+
export declare function isContentBranch({ tScope, node, }: {
|
|
6
|
+
tScope: string;
|
|
7
|
+
node: TSESTree.JSXAttribute;
|
|
8
|
+
}): boolean;
|
|
9
|
+
//# sourceMappingURL=branching-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branching-utils.d.ts","sourceRoot":"","sources":["../../src/utils/branching-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAepD;;GAEG;AACH,wBAAgB,eAAe,CAAC,EAC9B,MAAM,EACN,IAAI,GACL,EAAE;IACD,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,QAAQ,CAAC,YAAY,CAAC;CAC7B,GAAG,OAAO,CASV"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BRANCH_COMPONENT_NAME } from './constants.js';
|
|
2
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
3
|
+
const BRANCH_COMPONENT_BRANCH_PROPERTY = 'branch';
|
|
4
|
+
const PLURAL_COMPONENT_BRANCH_PROPERTY = 'n';
|
|
5
|
+
function getBranchingProp(name) {
|
|
6
|
+
return name === BRANCH_COMPONENT_NAME
|
|
7
|
+
? BRANCH_COMPONENT_BRANCH_PROPERTY
|
|
8
|
+
: PLURAL_COMPONENT_BRANCH_PROPERTY;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Returns true if the given branch is a content branch
|
|
12
|
+
*/
|
|
13
|
+
export function isContentBranch({ tScope, node, }) {
|
|
14
|
+
const propertyName = node.name.type === TSESTree.AST_NODE_TYPES.JSXIdentifier
|
|
15
|
+
? node.name.name
|
|
16
|
+
: null;
|
|
17
|
+
if (propertyName === getBranchingProp(tScope)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=branching-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"branching-utils.js","sourceRoot":"","sources":["../../src/utils/branching-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAA0B,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,MAAM,gCAAgC,GAAG,QAAQ,CAAC;AAClD,MAAM,gCAAgC,GAAG,GAAG,CAAC;AAE7C,SAAS,gBAAgB,CACvB,IAA6C;IAI7C,OAAO,IAAI,KAAK,qBAAqB;QACnC,CAAC,CAAC,gCAAgC;QAClC,CAAC,CAAC,gCAAgC,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,EAC9B,MAAM,EACN,IAAI,GAIL;IACC,MAAM,YAAY,GAChB,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,cAAc,CAAC,aAAa;QACtD,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;QAChB,CAAC,CAAC,IAAI,CAAC;IACX,IAAI,YAAY,KAAK,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
export declare const GT_LIBRARIES: string[];
|
|
3
|
+
export type GTLibrary = (typeof GT_LIBRARIES)[number];
|
|
4
|
+
export declare const T_COMPONENT_NAME = "T";
|
|
5
|
+
export declare const VAR_COMPONENT_NAME = "Var";
|
|
6
|
+
export declare const NUM_COMPONENT_NAME = "Num";
|
|
7
|
+
export declare const CURRENCY_COMPONENT_NAME = "Currency";
|
|
8
|
+
export declare const DATE_TIME_COMPONENT_NAME = "DateTime";
|
|
9
|
+
export declare const STATIC_COMPONENT_NAME = "Static";
|
|
10
|
+
export declare const BRANCH_COMPONENT_NAME = "Branch";
|
|
11
|
+
export declare const PLURAL_COMPONENT_NAME = "Plural";
|
|
12
|
+
export declare const USE_GT_FUNCTION_NAME = "useGT";
|
|
13
|
+
export declare const GET_GT_FUNCTION_NAME = "getGT";
|
|
14
|
+
export declare const USE_TRANSLATIONS_FUNCTION_NAME = "useTranslations";
|
|
15
|
+
export declare const GET_TRANSLATIONS_FUNCTION_NAME = "getTranslations";
|
|
16
|
+
export declare const USE_MESSAGES_FUNCTION_NAME = "useMessages";
|
|
17
|
+
export declare const GET_MESSAGES_FUNCTION_NAME = "getMessages";
|
|
18
|
+
export declare const MSG_FUNCTION_NAME = "msg";
|
|
19
|
+
export declare const DECLARE_STATIC_FUNCTION_NAME = "declareStatic";
|
|
20
|
+
export declare const GT_COMPONENT_NAMES: string[];
|
|
21
|
+
export declare const VARIABLE_COMPONENT_NAMES: string[];
|
|
22
|
+
export declare const BRANCH_COMPONENT_NAMES: string[];
|
|
23
|
+
export declare const GT_CALLBACK_DECLARATOR_FUNCTION_NAMES: string[];
|
|
24
|
+
export declare const ALLOWED_JSX_EXPRESSIONS: TSESTree.AST_NODE_TYPES[];
|
|
25
|
+
export declare const ALLOWED_BRANCH_ATTRIBUTE_JSX_EXPRESSIONS: TSESTree.AST_NODE_TYPES[];
|
|
26
|
+
export declare const RULE_URL = "https://generaltranslation.com/docs/react-core-linter/rules/";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
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
export const GT_LIBRARIES = [
|
|
3
|
+
'gt-react',
|
|
4
|
+
'gt-next',
|
|
5
|
+
'gt-react-native',
|
|
6
|
+
'gt-i18n',
|
|
7
|
+
'@generaltranslation/react-core',
|
|
8
|
+
];
|
|
9
|
+
// Components
|
|
10
|
+
export const T_COMPONENT_NAME = 'T';
|
|
11
|
+
export const VAR_COMPONENT_NAME = 'Var';
|
|
12
|
+
export const NUM_COMPONENT_NAME = 'Num';
|
|
13
|
+
export const CURRENCY_COMPONENT_NAME = 'Currency';
|
|
14
|
+
export const DATE_TIME_COMPONENT_NAME = 'DateTime';
|
|
15
|
+
export const STATIC_COMPONENT_NAME = 'Static';
|
|
16
|
+
export const BRANCH_COMPONENT_NAME = 'Branch';
|
|
17
|
+
export const PLURAL_COMPONENT_NAME = 'Plural';
|
|
18
|
+
// Functions
|
|
19
|
+
export const USE_GT_FUNCTION_NAME = 'useGT';
|
|
20
|
+
export const GET_GT_FUNCTION_NAME = 'getGT';
|
|
21
|
+
export const USE_TRANSLATIONS_FUNCTION_NAME = 'useTranslations';
|
|
22
|
+
export const GET_TRANSLATIONS_FUNCTION_NAME = 'getTranslations';
|
|
23
|
+
export const USE_MESSAGES_FUNCTION_NAME = 'useMessages';
|
|
24
|
+
export const GET_MESSAGES_FUNCTION_NAME = 'getMessages';
|
|
25
|
+
export const MSG_FUNCTION_NAME = 'msg';
|
|
26
|
+
export const DECLARE_STATIC_FUNCTION_NAME = 'declareStatic';
|
|
27
|
+
export const GT_COMPONENT_NAMES = [
|
|
28
|
+
T_COMPONENT_NAME,
|
|
29
|
+
VAR_COMPONENT_NAME,
|
|
30
|
+
NUM_COMPONENT_NAME,
|
|
31
|
+
CURRENCY_COMPONENT_NAME,
|
|
32
|
+
DATE_TIME_COMPONENT_NAME,
|
|
33
|
+
STATIC_COMPONENT_NAME,
|
|
34
|
+
];
|
|
35
|
+
export const VARIABLE_COMPONENT_NAMES = [
|
|
36
|
+
VAR_COMPONENT_NAME,
|
|
37
|
+
NUM_COMPONENT_NAME,
|
|
38
|
+
CURRENCY_COMPONENT_NAME,
|
|
39
|
+
DATE_TIME_COMPONENT_NAME,
|
|
40
|
+
];
|
|
41
|
+
export const BRANCH_COMPONENT_NAMES = [
|
|
42
|
+
BRANCH_COMPONENT_NAME,
|
|
43
|
+
PLURAL_COMPONENT_NAME,
|
|
44
|
+
];
|
|
45
|
+
// const gt = useGT(); const gt = await getGT();
|
|
46
|
+
export const GT_CALLBACK_DECLARATOR_FUNCTION_NAMES = [
|
|
47
|
+
USE_GT_FUNCTION_NAME,
|
|
48
|
+
GET_GT_FUNCTION_NAME,
|
|
49
|
+
];
|
|
50
|
+
// Error: any non-string literal, number literal, boolean literal, null literal, template literal (no interpolation)
|
|
51
|
+
export const ALLOWED_JSX_EXPRESSIONS = [
|
|
52
|
+
TSESTree.AST_NODE_TYPES.Literal,
|
|
53
|
+
TSESTree.AST_NODE_TYPES.TemplateLiteral,
|
|
54
|
+
];
|
|
55
|
+
// For branch attributes, we allow:
|
|
56
|
+
// Literal, TemplateLiteral (no interpolation), Jsx Stuff
|
|
57
|
+
export const ALLOWED_BRANCH_ATTRIBUTE_JSX_EXPRESSIONS = [
|
|
58
|
+
...ALLOWED_JSX_EXPRESSIONS,
|
|
59
|
+
TSESTree.AST_NODE_TYPES.JSXElement,
|
|
60
|
+
TSESTree.AST_NODE_TYPES.JSXFragment,
|
|
61
|
+
];
|
|
62
|
+
export const RULE_URL = 'https://generaltranslation.com/docs/react-core-linter/rules/';
|
|
63
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,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,CAAC;AAEF,gDAAgD;AAChD,MAAM,CAAC,MAAM,qCAAqC,GAAG;IACnD,oBAAoB;IACpB,oBAAoB;CACrB,CAAC;AAEF,oHAAoH;AACpH,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,QAAQ,CAAC,cAAc,CAAC,OAAO;IAC/B,QAAQ,CAAC,cAAc,CAAC,eAAe;CACxC,CAAC;AAEF,mCAAmC;AACnC,yDAAyD;AACzD,MAAM,CAAC,MAAM,wCAAwC,GAAG;IACtD,GAAG,uBAAuB;IAC1B,QAAQ,CAAC,cAAc,CAAC,UAAU;IAClC,QAAQ,CAAC,cAAc,CAAC,WAAW;CACpC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GACnB,8DAA8D,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import { GT_COMPONENT_NAMES, GTLibrary } from './constants.js';
|
|
3
|
+
import { RuleContext } from '@typescript-eslint/utils/ts-eslint';
|
|
4
|
+
export type IsGTFunctionOptions = {
|
|
5
|
+
context: Readonly<RuleContext<any, any>>;
|
|
6
|
+
/** Opening or closing element of the component
|
|
7
|
+
* TODO: make this more selective (eg differentiate btwn JSX and Function calls)
|
|
8
|
+
*/
|
|
9
|
+
node: TSESTree.JSXOpeningElement | TSESTree.JSXClosingElement | TSESTree.CallExpression;
|
|
10
|
+
libs: readonly GTLibrary[];
|
|
11
|
+
targetName: (typeof GT_COMPONENT_NAMES)[number] | (typeof GT_COMPONENT_NAMES)[number][];
|
|
12
|
+
};
|
|
13
|
+
export declare function isGTFunction({ context, node, libs, targetName, }: IsGTFunctionOptions): boolean;
|
|
14
|
+
export declare function isTComponent({ context, node, libs, }: Omit<IsGTFunctionOptions, 'targetName'>): boolean;
|
|
15
|
+
export declare function isStaticComponent({ context, node, libs, }: Omit<IsGTFunctionOptions, 'targetName'>): boolean;
|
|
16
|
+
export declare function isVariableComponent({ context, node, libs, }: Omit<IsGTFunctionOptions, 'targetName'>): boolean;
|
|
17
|
+
export declare function isBranchComponent({ context, node, libs, }: Omit<IsGTFunctionOptions, 'targetName'>): boolean;
|
|
18
|
+
export declare function isPluralComponent({ context, node, libs, }: Omit<IsGTFunctionOptions, 'targetName'>): boolean;
|
|
19
|
+
export declare function isBranchingComponent({ context, node, libs, }: Omit<IsGTFunctionOptions, 'targetName'>): boolean;
|
|
20
|
+
export declare function isDeclareStaticFunction({ context, node, libs, }: Omit<IsGTFunctionOptions, 'targetName'>): boolean;
|
|
21
|
+
export declare function isMsgFunction({ context, node, libs, }: Omit<IsGTFunctionOptions, 'targetName'>): boolean;
|
|
22
|
+
export declare function isGTCallbackFunction({ context, node, libs, }: Omit<IsGTFunctionOptions, 'targetName'>): boolean;
|
|
23
|
+
//# sourceMappingURL=isGTFunction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isGTFunction.d.ts","sourceRoot":"","sources":["../../src/utils/isGTFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EACL,kBAAkB,EAClB,SAAS,EAUV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAAS,MAAM,oCAAoC,CAAC;AAExE,MAAM,MAAM,mBAAmB,GAAG;IAEhC,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IACzC;;OAEG;IACH,IAAI,EACA,QAAQ,CAAC,iBAAiB,GAC1B,QAAQ,CAAC,iBAAiB,GAC1B,QAAQ,CAAC,cAAc,CAAC;IAC5B,IAAI,EAAE,SAAS,SAAS,EAAE,CAAC;IAC3B,UAAU,EACN,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,GACnC,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;CAC3C,CAAC;AA+BF,wBAAgB,YAAY,CA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EAAE,YAAY,CAAC,GAAG,OAAO,CAgEnD"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
2
|
+
import { T_COMPONENT_NAME, VARIABLE_COMPONENT_NAMES, PLURAL_COMPONENT_NAME, BRANCH_COMPONENT_NAME, BRANCH_COMPONENT_NAMES, STATIC_COMPONENT_NAME, DECLARE_STATIC_FUNCTION_NAME, MSG_FUNCTION_NAME, GT_CALLBACK_DECLARATOR_FUNCTION_NAMES, } from './constants.js';
|
|
3
|
+
/**
|
|
4
|
+
* Extract identifier name from a node
|
|
5
|
+
* @param node - JSXOpeningElement, JSXClosingElement, or CallExpression
|
|
6
|
+
* @returns
|
|
7
|
+
*
|
|
8
|
+
* TODO: handle member expressions
|
|
9
|
+
*/
|
|
10
|
+
function getIdentifierName(node) {
|
|
11
|
+
if (node.type === AST_NODE_TYPES.JSXOpeningElement ||
|
|
12
|
+
node.type === AST_NODE_TYPES.JSXClosingElement) {
|
|
13
|
+
if (node.name.type === AST_NODE_TYPES.JSXIdentifier) {
|
|
14
|
+
return node.name.name;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
else if (node.type === AST_NODE_TYPES.CallExpression) {
|
|
18
|
+
if (node.callee.type === AST_NODE_TYPES.Identifier) {
|
|
19
|
+
return node.callee.name;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
export function isGTFunction({ context, node, libs, targetName, }) {
|
|
25
|
+
// Get the name of the identifier
|
|
26
|
+
const identifierName = getIdentifierName(node);
|
|
27
|
+
if (identifierName === null)
|
|
28
|
+
return false;
|
|
29
|
+
// Get the scope
|
|
30
|
+
let scope = context.sourceCode.getScope(node);
|
|
31
|
+
let variable;
|
|
32
|
+
while (scope) {
|
|
33
|
+
variable = scope.set.get(identifierName);
|
|
34
|
+
if (variable)
|
|
35
|
+
break;
|
|
36
|
+
scope = scope.upper;
|
|
37
|
+
}
|
|
38
|
+
if (!variable) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
// Check import type
|
|
42
|
+
if (variable.defs.length === 0 ||
|
|
43
|
+
variable.defs[0].type !== 'ImportBinding' ||
|
|
44
|
+
variable.defs[0].node.type !== AST_NODE_TYPES.ImportSpecifier) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
// Check name (eg T as GT, Var, etc)
|
|
48
|
+
const resolvedImportName = variable.defs[0].node.imported.type === AST_NODE_TYPES.Identifier
|
|
49
|
+
? variable.defs[0].node.imported.name
|
|
50
|
+
: variable.defs[0].node.imported.value;
|
|
51
|
+
if ((typeof targetName === 'string' && resolvedImportName !== targetName) ||
|
|
52
|
+
(Array.isArray(targetName) &&
|
|
53
|
+
!targetName.includes(resolvedImportName))) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
// Check import source
|
|
57
|
+
const importDecl = variable.defs[0].parent;
|
|
58
|
+
if (importDecl.type !== AST_NODE_TYPES.ImportDeclaration ||
|
|
59
|
+
!libs.includes(importDecl.source.value)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
export function isTComponent({ context, node, libs, }) {
|
|
65
|
+
return isGTFunction({
|
|
66
|
+
context,
|
|
67
|
+
node,
|
|
68
|
+
libs,
|
|
69
|
+
targetName: T_COMPONENT_NAME,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
export function isStaticComponent({ context, node, libs, }) {
|
|
73
|
+
return isGTFunction({
|
|
74
|
+
context,
|
|
75
|
+
node,
|
|
76
|
+
libs,
|
|
77
|
+
targetName: STATIC_COMPONENT_NAME,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
export function isVariableComponent({ context, node, libs, }) {
|
|
81
|
+
return isGTFunction({
|
|
82
|
+
context,
|
|
83
|
+
node,
|
|
84
|
+
libs,
|
|
85
|
+
targetName: VARIABLE_COMPONENT_NAMES,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
export function isBranchComponent({ context, node, libs, }) {
|
|
89
|
+
return isGTFunction({
|
|
90
|
+
context,
|
|
91
|
+
node,
|
|
92
|
+
libs,
|
|
93
|
+
targetName: BRANCH_COMPONENT_NAME,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
export function isPluralComponent({ context, node, libs, }) {
|
|
97
|
+
return isGTFunction({
|
|
98
|
+
context,
|
|
99
|
+
node,
|
|
100
|
+
libs,
|
|
101
|
+
targetName: PLURAL_COMPONENT_NAME,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
export function isBranchingComponent({ context, node, libs, }) {
|
|
105
|
+
return isGTFunction({
|
|
106
|
+
context,
|
|
107
|
+
node,
|
|
108
|
+
libs,
|
|
109
|
+
targetName: BRANCH_COMPONENT_NAMES,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
export function isDeclareStaticFunction({ context, node, libs, }) {
|
|
113
|
+
return isGTFunction({
|
|
114
|
+
context,
|
|
115
|
+
node,
|
|
116
|
+
libs,
|
|
117
|
+
targetName: DECLARE_STATIC_FUNCTION_NAME,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
export function isMsgFunction({ context, node, libs, }) {
|
|
121
|
+
return isGTFunction({
|
|
122
|
+
context,
|
|
123
|
+
node,
|
|
124
|
+
libs,
|
|
125
|
+
targetName: MSG_FUNCTION_NAME,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
export function isGTCallbackFunction({ context, node, libs, }) {
|
|
129
|
+
// -- Step 1: Get binding for the gt identifier -- //
|
|
130
|
+
const identifierName = getIdentifierName(node);
|
|
131
|
+
if (identifierName === null)
|
|
132
|
+
return false;
|
|
133
|
+
if (identifierName === 'gt') {
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
// Find the variable declaration in scope
|
|
137
|
+
let scope = context.sourceCode.getScope(node);
|
|
138
|
+
let variable;
|
|
139
|
+
while (scope) {
|
|
140
|
+
variable = scope.set.get(identifierName);
|
|
141
|
+
if (variable)
|
|
142
|
+
break;
|
|
143
|
+
scope = scope.upper;
|
|
144
|
+
}
|
|
145
|
+
if (!variable) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
// -- Step 2: Check if the variable was declared with useGT() or await getGT() -- //
|
|
149
|
+
// Helper function
|
|
150
|
+
function isGTDeclaratorCallExpression(node) {
|
|
151
|
+
return isGTFunction({
|
|
152
|
+
context,
|
|
153
|
+
node,
|
|
154
|
+
libs,
|
|
155
|
+
targetName: GT_CALLBACK_DECLARATOR_FUNCTION_NAMES,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
// Find the first variable declarator definition (const gt = ...)
|
|
159
|
+
const variableDef = variable.defs.find((def) => def.type === 'Variable' &&
|
|
160
|
+
def.node.type === AST_NODE_TYPES.VariableDeclarator);
|
|
161
|
+
const init = variableDef?.node.init;
|
|
162
|
+
if (!init)
|
|
163
|
+
return false;
|
|
164
|
+
// -- Step 3: Check the import -- //
|
|
165
|
+
// Case 1: const gt = useGT()
|
|
166
|
+
if (init.type === AST_NODE_TYPES.CallExpression &&
|
|
167
|
+
isGTDeclaratorCallExpression(init)) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
// Case 2: const gt = await getGT()
|
|
171
|
+
if (libs.includes('gt-next') &&
|
|
172
|
+
init.type === AST_NODE_TYPES.AwaitExpression &&
|
|
173
|
+
init.argument.type === AST_NODE_TYPES.CallExpression &&
|
|
174
|
+
isGTDeclaratorCallExpression(init.argument)) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=isGTFunction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isGTFunction.js","sourceRoot":"","sources":["../../src/utils/isGTFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAY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,IAAI,KAAK,UAAU;QACvB,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,kBAAkB,CACF,CAAC;IACtD,MAAM,IAAI,GAAG,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC;IACpC,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAC;IAExB,oCAAoC;IAEpC,6BAA6B;IAC7B,IACE,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,cAAc;QAC3C,4BAA4B,CAAC,IAAI,CAAC,EAClC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,mCAAmC;IACnC,IACE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;QACxB,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,eAAe;QAC5C,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,cAAc,CAAC,cAAc;QACpD,4BAA4B,CAAC,IAAI,CAAC,QAAQ,CAAC,EAC3C,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@generaltranslation/react-core-linter",
|
|
3
|
+
"version": "0.0.0-alpha.0",
|
|
4
|
+
"description": "ESLint plugin for General Translation React Core integration",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"keywords": [
|
|
20
|
+
"eslint",
|
|
21
|
+
"eslintplugin",
|
|
22
|
+
"eslint-plugin",
|
|
23
|
+
"react-core",
|
|
24
|
+
"translation",
|
|
25
|
+
"internationalization",
|
|
26
|
+
"i18n",
|
|
27
|
+
"jsx",
|
|
28
|
+
"react",
|
|
29
|
+
"typescript"
|
|
30
|
+
],
|
|
31
|
+
"author": "General Translation, Inc.",
|
|
32
|
+
"license": "FSL-1.1-ALv2",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/generaltranslation/gt.git",
|
|
36
|
+
"directory": "packages/react-core-linter"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/generaltranslation/gt/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://generaltranslation.com/",
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=18.0.0"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
47
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
48
|
+
"eslint": "^8.0.0 || ^9.0.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/eslint": "^8.56.0",
|
|
52
|
+
"@types/estree": "^1.0.8",
|
|
53
|
+
"@types/estree-jsx": "^1.0.5",
|
|
54
|
+
"@types/node": "^20.0.0",
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
56
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
57
|
+
"@typescript-eslint/rule-tester": "^8.50.1",
|
|
58
|
+
"eslint": "^9.0.0",
|
|
59
|
+
"typescript": "^5.0.0",
|
|
60
|
+
"vitest": "^2.0.0"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"@typescript-eslint/utils": "^8.50.1"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"patch": "pnpm version patch",
|
|
67
|
+
"transpile": "tsc",
|
|
68
|
+
"build": "pnpm run transpile",
|
|
69
|
+
"build:clean": "sh ../../scripts/clean.sh && pnpm run build",
|
|
70
|
+
"build:release": "pnpm run build:clean",
|
|
71
|
+
"dev": "tsc --watch",
|
|
72
|
+
"release": "pnpm run build:clean && pnpm publish",
|
|
73
|
+
"release:alpha": "pnpm run build:clean && pnpm publish --tag alpha",
|
|
74
|
+
"release:beta": "pnpm run build:clean && pnpm publish --tag beta",
|
|
75
|
+
"release:latest": "pnpm run build:clean && pnpm publish --tag latest",
|
|
76
|
+
"lint": "eslint \"src/**/*.{js,ts,tsx}\" \"**/__tests__/**/*.{js,ts,tsx}\"",
|
|
77
|
+
"lint:fix": "eslint \"src/**/*.{js,ts,tsx}\" \"**/__tests__/**/*.{js,ts,tsx}\" --fix",
|
|
78
|
+
"test": "vitest run",
|
|
79
|
+
"test:watch": "vitest"
|
|
80
|
+
}
|
|
81
|
+
}
|