eslint-plugin-cvsdk-rules 10.0.1-test → 10.1.0-alpha.1
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/build/index.d.ts +8 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +11 -0
- package/build/index.js.map +1 -0
- package/build/rules/prefer-self-over-window.d.ts +3 -0
- package/build/rules/prefer-self-over-window.d.ts.map +1 -0
- package/build/rules/prefer-self-over-window.js +38 -0
- package/build/rules/prefer-self-over-window.js.map +1 -0
- package/build/rules/prefer-txml-over-domparser.d.ts +3 -0
- package/build/rules/prefer-txml-over-domparser.d.ts.map +1 -0
- package/build/rules/prefer-txml-over-domparser.js +27 -0
- package/build/rules/prefer-txml-over-domparser.js.map +1 -0
- package/jest.config.js +40 -2
- package/package.json +16 -8
- package/src/index.ts +13 -0
- package/{rules/prefer-self-over-window.spec.js → src/rules/prefer-self-over-window.spec.ts} +15 -10
- package/src/rules/prefer-self-over-window.ts +41 -0
- package/src/rules/prefer-txml-over-domparser.ts +28 -0
- package/tsconfig.json +25 -0
- package/config/file.ts +0 -1
- package/config/tsconfig.json +0 -11
- package/index.js +0 -6
- package/rules/prefer-self-over-window.js +0 -41
- package/rules/prefer-txml-over-domparser.js +0 -26
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const plugin: {
|
|
2
|
+
rules: {
|
|
3
|
+
'prefer-self-over-window': import("@typescript-eslint/utils/dist/ts-eslint/Rule.js").RuleModule<"forbiddenWindowAccess", never[], unknown, import("@typescript-eslint/utils/dist/ts-eslint/Rule.js").RuleListener>;
|
|
4
|
+
'prefer-txml-over-domparser': import("@typescript-eslint/utils/dist/ts-eslint/Rule.js").RuleModule<"forbiddenDomParserUsage", never[], unknown, import("@typescript-eslint/utils/dist/ts-eslint/Rule.js").RuleListener>;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
export { plugin };
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,QAAA,MAAM,MAAM;;;;;CAEX,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { rule as preferSelfOverWindow } from './rules/prefer-self-over-window.js';
|
|
2
|
+
import { rule as preferTxmlOverDomParser } from './rules/prefer-txml-over-domparser.js';
|
|
3
|
+
var rules = {
|
|
4
|
+
'prefer-self-over-window': preferSelfOverWindow,
|
|
5
|
+
'prefer-txml-over-domparser': preferTxmlOverDomParser,
|
|
6
|
+
};
|
|
7
|
+
var plugin = {
|
|
8
|
+
rules: rules,
|
|
9
|
+
};
|
|
10
|
+
export { plugin };
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAClF,OAAO,EAAE,IAAI,IAAI,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAExF,IAAM,KAAK,GAAG;IACV,yBAAyB,EAAE,oBAAoB;IAC/C,4BAA4B,EAAE,uBAAuB;CACxD,CAAC;AAEF,IAAM,MAAM,GAAG;IACX,KAAK,OAAA;CACR,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-self-over-window.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-self-over-window.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiB,MAAM,0BAA0B,CAAC;AAItE,eAAO,MAAM,IAAI,6FAoCf,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
var createRule = ESLintUtils.RuleCreator(function (name) { return name; });
|
|
3
|
+
export var rule = createRule({
|
|
4
|
+
create: function (context) {
|
|
5
|
+
var parserServices = ESLintUtils.getParserServices(context);
|
|
6
|
+
function reportWindowError(node) {
|
|
7
|
+
if (node.parent.type !== 'VariableDeclarator') {
|
|
8
|
+
var nodeType = parserServices.getTypeAtLocation(node);
|
|
9
|
+
if (Object.prototype.hasOwnProperty.call(nodeType, 'aliasSymbol')) {
|
|
10
|
+
context.report({
|
|
11
|
+
messageId: 'forbiddenWindowAccess',
|
|
12
|
+
node: node,
|
|
13
|
+
fix: function (fixer) {
|
|
14
|
+
return fixer.replaceText(node, 'self');
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
"Identifier[name='window']": reportWindowError,
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
name: 'uppercase-first-declarations',
|
|
25
|
+
meta: {
|
|
26
|
+
docs: {
|
|
27
|
+
description: 'Disallow window access.',
|
|
28
|
+
},
|
|
29
|
+
messages: {
|
|
30
|
+
forbiddenWindowAccess: '`window` cannot be accessed inside some containers, we prefer using `self` as it has more compatibility.',
|
|
31
|
+
},
|
|
32
|
+
schema: [],
|
|
33
|
+
type: 'problem',
|
|
34
|
+
fixable: 'code',
|
|
35
|
+
},
|
|
36
|
+
defaultOptions: [],
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=prefer-self-over-window.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-self-over-window.js","sourceRoot":"","sources":["../../src/rules/prefer-self-over-window.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiB,MAAM,0BAA0B,CAAC;AAEtE,IAAM,UAAU,GAAG,WAAW,CAAC,WAAW,CAAC,UAAC,IAAI,IAAK,OAAA,IAAI,EAAJ,CAAI,CAAC,CAAC;AAE3D,MAAM,CAAC,IAAM,IAAI,GAAG,UAAU,CAAC;IAC3B,MAAM,YAAC,OAAO;QACV,IAAM,cAAc,GAAG,WAAW,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAE9D,SAAS,iBAAiB,CAAC,IAAmB;YAC1C,IAAI,IAAI,CAAC,MAAO,CAAC,IAAI,KAAK,oBAAoB,EAAE;gBAC5C,IAAM,QAAQ,GAAG,cAAc,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;gBACxD,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,EAAE,aAAa,CAAC,EAAE;oBAC/D,OAAO,CAAC,MAAM,CAAC;wBACX,SAAS,EAAE,uBAAuB;wBAClC,IAAI,MAAA;wBACJ,GAAG,EAAE,UAAU,KAAK;4BAChB,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;wBAC3C,CAAC;qBACJ,CAAC,CAAC;iBACN;aACJ;QACL,CAAC;QAED,OAAO;YACH,2BAA2B,EAAE,iBAAiB;SACjD,CAAC;IACN,CAAC;IACD,IAAI,EAAE,8BAA8B;IACpC,IAAI,EAAE;QACF,IAAI,EAAE;YACF,WAAW,EAAE,yBAAyB;SACzC;QACD,QAAQ,EAAE;YACN,qBAAqB,EAAE,0GAA0G;SACpI;QACD,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,MAAM;KAClB;IACD,cAAc,EAAE,EAAE;CACrB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-txml-over-domparser.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-txml-over-domparser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAIvD,eAAO,MAAM,IAAI,+FAuBf,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
var createRule = ESLintUtils.RuleCreator(function (name) { return name; });
|
|
3
|
+
export var rule = createRule({
|
|
4
|
+
create: function (context) {
|
|
5
|
+
return {
|
|
6
|
+
Identifier: function (node) {
|
|
7
|
+
if (node.type === 'Identifier' && node.name === 'DOMParser' && node.parent.type === 'NewExpression') {
|
|
8
|
+
context.report({
|
|
9
|
+
node: node,
|
|
10
|
+
messageId: 'forbiddenDomParserUsage',
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
},
|
|
16
|
+
name: 'prefer-txml-over-domparser',
|
|
17
|
+
meta: {
|
|
18
|
+
docs: { description: 'Disallow DOMParser usage.' },
|
|
19
|
+
messages: {
|
|
20
|
+
forbiddenDomParserUsage: "Prefer using txml (https://www.npmjs.com/package/txml) over DOMParser as DOMParser isn't supported on ION.",
|
|
21
|
+
},
|
|
22
|
+
schema: [],
|
|
23
|
+
type: 'problem',
|
|
24
|
+
},
|
|
25
|
+
defaultOptions: [],
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=prefer-txml-over-domparser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-txml-over-domparser.js","sourceRoot":"","sources":["../../src/rules/prefer-txml-over-domparser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,IAAM,UAAU,GAAG,WAAW,CAAC,WAAW,CAAC,UAAC,IAAI,IAAK,OAAA,IAAI,EAAJ,CAAI,CAAC,CAAC;AAE3D,MAAM,CAAC,IAAM,IAAI,GAAG,UAAU,CAAC;IAC3B,MAAM,YAAC,OAAO;QACV,OAAO;YACH,UAAU,YAAC,IAAI;gBACX,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,eAAe,EAAE;oBACjG,OAAO,CAAC,MAAM,CAAC;wBACX,IAAI,MAAA;wBACJ,SAAS,EAAE,yBAAyB;qBACvC,CAAC,CAAC;iBACN;YACL,CAAC;SACJ,CAAC;IACN,CAAC;IACD,IAAI,EAAE,4BAA4B;IAClC,IAAI,EAAE;QACF,IAAI,EAAE,EAAE,WAAW,EAAE,2BAA2B,EAAE;QAClD,QAAQ,EAAE;YACN,uBAAuB,EAAE,4GAA4G;SACxI;QACD,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,SAAS;KAClB;IACD,cAAc,EAAE,EAAE;CACrB,CAAC,CAAC"}
|
package/jest.config.js
CHANGED
|
@@ -1,2 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
collectCoverage: false,
|
|
5
|
+
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
|
|
6
|
+
coverageReporters: ['lcov'],
|
|
7
|
+
moduleFileExtensions: [
|
|
8
|
+
'ts',
|
|
9
|
+
'tsx',
|
|
10
|
+
'mts',
|
|
11
|
+
'mtsx',
|
|
12
|
+
'cjs',
|
|
13
|
+
'js',
|
|
14
|
+
'jsx',
|
|
15
|
+
'mjs',
|
|
16
|
+
'mjsx',
|
|
17
|
+
'json',
|
|
18
|
+
'node',
|
|
19
|
+
],
|
|
20
|
+
setupFilesAfterEnv: [
|
|
21
|
+
path.join(path.resolve(), 'node_modules/console-fail-test/setup.cjs'),
|
|
22
|
+
],
|
|
23
|
+
testRegex: ['./tests/.+\\.test\\.ts$', './src/rules/.+\\.spec\\.ts$'],
|
|
24
|
+
transform: {
|
|
25
|
+
'^.+\\.(t|j)sx?$': [
|
|
26
|
+
'@swc/jest',
|
|
27
|
+
{
|
|
28
|
+
jsc: {
|
|
29
|
+
target: 'es2019',
|
|
30
|
+
transform: {
|
|
31
|
+
react: {
|
|
32
|
+
runtime: 'automatic',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
workerIdleMemoryLimit: '300MB',
|
|
40
|
+
};
|
package/package.json
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-cvsdk-rules",
|
|
3
|
-
"version": "10.0.1
|
|
4
|
-
"main": "index.js",
|
|
3
|
+
"version": "10.1.0-alpha.1",
|
|
4
|
+
"main": "./build/index.js",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"scripts": {
|
|
6
7
|
"test": "jest",
|
|
7
|
-
"test:nocoverage": "jest"
|
|
8
|
+
"test:nocoverage": "jest",
|
|
9
|
+
"build": "tsc"
|
|
8
10
|
},
|
|
9
11
|
"dependencies": {
|
|
10
|
-
"
|
|
11
|
-
"eslint": "8.54.0"
|
|
12
|
+
"typescript-eslint": "8.8.0"
|
|
12
13
|
},
|
|
13
14
|
"devDependencies": {
|
|
14
|
-
"@
|
|
15
|
-
"
|
|
15
|
+
"@eslint/js": "^9.8.0",
|
|
16
|
+
"@types/eslint": "^9.6.0",
|
|
17
|
+
"@types/eslint__js": "^8.42.3",
|
|
18
|
+
"@types/node": "^22.0.2",
|
|
19
|
+
"@typescript-eslint/rule-tester": "8.8.0",
|
|
20
|
+
"console-fail-test": "^0.5.0",
|
|
21
|
+
"eslint": "^9.8.0",
|
|
22
|
+
"eslint-plugin-eslint-plugin": "6.2.0",
|
|
23
|
+
"typescript": "5.0.2"
|
|
16
24
|
},
|
|
17
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "eeeebc7abe4c932c8074c1b886786fc4369508cb"
|
|
18
26
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { rule as preferSelfOverWindow } from './rules/prefer-self-over-window.js';
|
|
2
|
+
import { rule as preferTxmlOverDomParser } from './rules/prefer-txml-over-domparser.js';
|
|
3
|
+
|
|
4
|
+
const rules = {
|
|
5
|
+
'prefer-self-over-window': preferSelfOverWindow,
|
|
6
|
+
'prefer-txml-over-domparser': preferTxmlOverDomParser,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const plugin = {
|
|
10
|
+
rules,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { plugin };
|
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { RuleTester } from '@typescript-eslint/rule-tester';
|
|
2
|
+
import tseslint from 'typescript-eslint';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { rule } from '../../build/rules/prefer-self-over-window.js';
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const ruleName = 'prefer-self-over-window';
|
|
6
|
+
console.log(`Root dir: ${path.join(__dirname, '../..')}`);
|
|
7
7
|
|
|
8
8
|
// https://typescript-eslint.io/packages/rule-tester/#type-aware-testing
|
|
9
9
|
const ruleTester = new RuleTester({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
languageOptions: {
|
|
11
|
+
parser: tseslint.parser,
|
|
12
|
+
parserOptions: {
|
|
13
|
+
projectService: {
|
|
14
|
+
allowDefaultProject: ['*.ts*'],
|
|
15
|
+
defaultProject: 'tsconfig.json',
|
|
16
|
+
},
|
|
17
|
+
tsconfigRootDir: path.join(__dirname, '../..'),
|
|
18
|
+
},
|
|
14
19
|
},
|
|
15
20
|
});
|
|
16
21
|
|
|
17
22
|
describe('Disallow window access', () => {
|
|
18
|
-
ruleTester.run(
|
|
23
|
+
ruleTester.run('prefer-self-over-window', rule, {
|
|
19
24
|
invalid: [
|
|
20
25
|
{
|
|
21
26
|
code: 'window;',
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ESLintUtils, type TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
|
|
3
|
+
const createRule = ESLintUtils.RuleCreator((name) => name);
|
|
4
|
+
|
|
5
|
+
export const rule = createRule({
|
|
6
|
+
create(context) {
|
|
7
|
+
const parserServices = ESLintUtils.getParserServices(context);
|
|
8
|
+
|
|
9
|
+
function reportWindowError(node: TSESTree.Node) {
|
|
10
|
+
if (node.parent!.type !== 'VariableDeclarator') {
|
|
11
|
+
const nodeType = parserServices.getTypeAtLocation(node);
|
|
12
|
+
if (Object.prototype.hasOwnProperty.call(nodeType, 'aliasSymbol')) {
|
|
13
|
+
context.report({
|
|
14
|
+
messageId: 'forbiddenWindowAccess',
|
|
15
|
+
node,
|
|
16
|
+
fix: function (fixer) {
|
|
17
|
+
return fixer.replaceText(node, 'self');
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
"Identifier[name='window']": reportWindowError,
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
name: 'uppercase-first-declarations',
|
|
29
|
+
meta: {
|
|
30
|
+
docs: {
|
|
31
|
+
description: 'Disallow window access.',
|
|
32
|
+
},
|
|
33
|
+
messages: {
|
|
34
|
+
forbiddenWindowAccess: '`window` cannot be accessed inside some containers, we prefer using `self` as it has more compatibility.',
|
|
35
|
+
},
|
|
36
|
+
schema: [], // no options
|
|
37
|
+
type: 'problem',
|
|
38
|
+
fixable: 'code',
|
|
39
|
+
},
|
|
40
|
+
defaultOptions: [],
|
|
41
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
|
|
3
|
+
const createRule = ESLintUtils.RuleCreator((name) => name);
|
|
4
|
+
|
|
5
|
+
export const rule = createRule({
|
|
6
|
+
create(context) {
|
|
7
|
+
return {
|
|
8
|
+
Identifier(node) {
|
|
9
|
+
if (node.type === 'Identifier' && node.name === 'DOMParser' && node.parent.type === 'NewExpression') {
|
|
10
|
+
context.report({
|
|
11
|
+
node,
|
|
12
|
+
messageId: 'forbiddenDomParserUsage',
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
name: 'prefer-txml-over-domparser',
|
|
19
|
+
meta: {
|
|
20
|
+
docs: { description: 'Disallow DOMParser usage.' },
|
|
21
|
+
messages: {
|
|
22
|
+
forbiddenDomParserUsage: `Prefer using txml (https://www.npmjs.com/package/txml) over DOMParser as DOMParser isn't supported on ION.`,
|
|
23
|
+
},
|
|
24
|
+
schema: [],
|
|
25
|
+
type: 'problem',
|
|
26
|
+
},
|
|
27
|
+
defaultOptions: [],
|
|
28
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "esnext",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"outDir": "build",
|
|
6
|
+
"declarationMap": true,
|
|
7
|
+
"downlevelIteration": true,
|
|
8
|
+
"noImplicitAny": true,
|
|
9
|
+
"preserveConstEnums": true,
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"target": "es5",
|
|
12
|
+
"strict": true,
|
|
13
|
+
"noUnusedLocals": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"moduleResolution": "node",
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"importHelpers": true,
|
|
18
|
+
"esModuleInterop": true,
|
|
19
|
+
"jsx": "react",
|
|
20
|
+
"useDefineForClassFields": false,
|
|
21
|
+
"lib": ["dom", "dom.iterable", "es2017"]
|
|
22
|
+
},
|
|
23
|
+
"include": ["src/**/*.ts"],
|
|
24
|
+
"exclude": ["**/*.spec.ts"]
|
|
25
|
+
}
|
package/config/file.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// See: https://typescript-eslint.io/packages/rule-tester/#type-aware-testing
|
package/config/tsconfig.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// https://typescript-eslint.io/packages/rule-tester/#type-aware-testing
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
// Otherwise TS will complain it'll override the base project's output
|
|
5
|
-
"outDir": "./",
|
|
6
|
-
"strict": true
|
|
7
|
-
},
|
|
8
|
-
"exclude": [],
|
|
9
|
-
// See: https://typescript-eslint.io/packages/rule-tester/#type-aware-testing
|
|
10
|
-
"include": ["file.ts"]
|
|
11
|
-
}
|
package/index.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const { ESLintUtils } = require('@typescript-eslint/utils');
|
|
2
|
-
|
|
3
|
-
const meta = {
|
|
4
|
-
docs: {
|
|
5
|
-
description: 'Disallow window access.',
|
|
6
|
-
},
|
|
7
|
-
messages: {
|
|
8
|
-
forbiddenWindowAccess: '`window` cannot be accessed inside some containers, we prefer using `self` as it has more compatibility.',
|
|
9
|
-
},
|
|
10
|
-
schema: [], // no options
|
|
11
|
-
type: 'problem',
|
|
12
|
-
fixable: 'code',
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
function create(context) {
|
|
16
|
-
const parserServices = ESLintUtils.getParserServices(context);
|
|
17
|
-
|
|
18
|
-
function reportWindowError(node) {
|
|
19
|
-
if (node.parent.type !== 'VariableDeclarator') {
|
|
20
|
-
const nodeType = parserServices.getTypeAtLocation(node);
|
|
21
|
-
if (Object.prototype.hasOwnProperty.call(nodeType, 'aliasSymbol')) {
|
|
22
|
-
context.report({
|
|
23
|
-
messageId: 'forbiddenWindowAccess',
|
|
24
|
-
node,
|
|
25
|
-
fix: function (fixer) {
|
|
26
|
-
return fixer.replaceText(node, 'self');
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
"Identifier[name='window']": reportWindowError,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
module.exports = {
|
|
39
|
-
create,
|
|
40
|
-
meta,
|
|
41
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const meta = {
|
|
2
|
-
docs: 'Disallow DOMParser usage.',
|
|
3
|
-
messages: {
|
|
4
|
-
forbiddenDomParserUsage: `Prefer using txml (https://www.npmjs.com/package/txml) over DOMParser as DOMParser isn't supported on ION.`,
|
|
5
|
-
},
|
|
6
|
-
schema: [],
|
|
7
|
-
type: 'problem',
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
function create(context) {
|
|
11
|
-
return {
|
|
12
|
-
Identifier(node) {
|
|
13
|
-
if (node.type === 'Identifier' && node.name === 'DOMParser' && node.parent.type === 'NewExpression') {
|
|
14
|
-
context.report({
|
|
15
|
-
node,
|
|
16
|
-
messageId: 'forbiddenDomParserUsage',
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = {
|
|
24
|
-
create,
|
|
25
|
-
meta,
|
|
26
|
-
};
|