eslint-plugin-cvsdk-rules 10.0.0-1 → 10.0.0-ad-data-structure-refactor

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 CHANGED
@@ -1,5 +1,6 @@
1
1
  declare const plugin: {
2
2
  rules: {
3
+ 'prefer-no-lodash-cloneDeep': import("@typescript-eslint/utils/dist/ts-eslint/Rule.js").RuleModule<"forbiddenCloneDeepUsage", never[], unknown, import("@typescript-eslint/utils/dist/ts-eslint/Rule.js").RuleListener>;
3
4
  '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
5
  '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
  };
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,QAAA,MAAM,MAAM;;;;;;CAEX,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
package/build/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { rule as preferSelfOverWindow } from './rules/prefer-self-over-window.js';
2
2
  import { rule as preferTxmlOverDomParser } from './rules/prefer-txml-over-domparser.js';
3
+ import { rule as preferNoLodashCloneDeep } from './rules/prefer-no-lodash-clone-deep.js';
3
4
  var rules = {
5
+ 'prefer-no-lodash-cloneDeep': preferNoLodashCloneDeep,
4
6
  'prefer-self-over-window': preferSelfOverWindow,
5
7
  'prefer-txml-over-domparser': preferTxmlOverDomParser,
6
8
  };
@@ -1 +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"}
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;AACxF,OAAO,EAAE,IAAI,IAAI,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAEzF,IAAM,KAAK,GAAG;IACV,4BAA4B,EAAE,uBAAuB;IACrD,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,3 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ export declare const rule: ESLintUtils.RuleModule<"forbiddenCloneDeepUsage", never[], unknown, ESLintUtils.RuleListener>;
3
+ //# sourceMappingURL=prefer-no-lodash-clone-deep.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefer-no-lodash-clone-deep.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-no-lodash-clone-deep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAIvD,eAAO,MAAM,IAAI,+FAwBf,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
+ "Program:has(ImportDeclaration[source.value='lodash'] > ImportSpecifier[imported.name=cloneDeep]) CallExpression[callee.name=cloneDeep]": function (node) {
7
+ context.report({
8
+ node: node,
9
+ messageId: 'forbiddenCloneDeepUsage',
10
+ });
11
+ },
12
+ };
13
+ },
14
+ name: 'prefer-no-lodash-cloneDeep',
15
+ meta: {
16
+ docs: {
17
+ description: 'Detect usage of Lodash cloneDeep',
18
+ },
19
+ messages: {
20
+ forbiddenCloneDeepUsage: "Prefer using rfdc (@sky-uk-ott/core-video-sdk-js-external-rfdc) over lodash.cloneDeep as it cost a lot in performance",
21
+ },
22
+ schema: [],
23
+ type: 'problem',
24
+ },
25
+ defaultOptions: [],
26
+ });
27
+ //# sourceMappingURL=prefer-no-lodash-clone-deep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefer-no-lodash-clone-deep.js","sourceRoot":"","sources":["../../src/rules/prefer-no-lodash-clone-deep.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,wIAAwI,EACpI,UAAC,IAAI;gBACD,OAAO,CAAC,MAAM,CAAC;oBACX,IAAI,MAAA;oBACJ,SAAS,EAAE,yBAAyB;iBACvC,CAAC,CAAC;YACP,CAAC;SACR,CAAC;IACN,CAAC;IACD,IAAI,EAAE,4BAA4B;IAClC,IAAI,EAAE;QACF,IAAI,EAAE;YACF,WAAW,EAAE,kCAAkC;SAClD;QACD,QAAQ,EAAE;YACN,uBAAuB,EAAE,uHAAuH;SACnJ;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.0-1",
4
- "main": "index.js",
3
+ "version": "10.0.0-ad-data-structure-refactor",
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
- "@typescript-eslint/utils": "6.21.0",
11
- "eslint": "8.54.0"
12
+ "typescript-eslint": "8.8.0"
12
13
  },
13
14
  "devDependencies": {
14
- "@typescript-eslint/rule-tester": "6.21.0",
15
- "jest": "29.7.0"
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": "3c2af8c7ba90a6e1e23a0f80b2d4c4026edf9598"
25
+ "gitHead": "e366ef8405f417954fda5abd269d1f624508ccc9"
18
26
  }
package/src/index.ts ADDED
@@ -0,0 +1,15 @@
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
+ import { rule as preferNoLodashCloneDeep } from './rules/prefer-no-lodash-clone-deep.js';
4
+
5
+ const rules = {
6
+ 'prefer-no-lodash-cloneDeep': preferNoLodashCloneDeep,
7
+ 'prefer-self-over-window': preferSelfOverWindow,
8
+ 'prefer-txml-over-domparser': preferTxmlOverDomParser,
9
+ };
10
+
11
+ const plugin = {
12
+ rules,
13
+ };
14
+
15
+ export { plugin };
@@ -0,0 +1,29 @@
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
+ "Program:has(ImportDeclaration[source.value='lodash'] > ImportSpecifier[imported.name=cloneDeep]) CallExpression[callee.name=cloneDeep]":
9
+ (node) => {
10
+ context.report({
11
+ node,
12
+ messageId: 'forbiddenCloneDeepUsage',
13
+ });
14
+ },
15
+ };
16
+ },
17
+ name: 'prefer-no-lodash-cloneDeep',
18
+ meta: {
19
+ docs: {
20
+ description: 'Detect usage of Lodash cloneDeep',
21
+ },
22
+ messages: {
23
+ forbiddenCloneDeepUsage: `Prefer using rfdc (@sky-uk-ott/core-video-sdk-js-external-rfdc) over lodash.cloneDeep as it cost a lot in performance`,
24
+ },
25
+ schema: [],
26
+ type: 'problem',
27
+ },
28
+ defaultOptions: [],
29
+ });
@@ -1,21 +1,26 @@
1
- const { RuleTester } = require('@typescript-eslint/rule-tester');
2
- const path = require('path');
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
- const rule = require('./prefer-self-over-window');
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
- parser: require.resolve('@typescript-eslint/parser'),
11
- parserOptions: {
12
- project: true,
13
- tsconfigRootDir: path.join(__dirname, '../config'),
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(ruleName, rule, {
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
@@ -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,6 +0,0 @@
1
- module.exports = {
2
- rules: {
3
- 'prefer-self-over-window': require('./rules/prefer-self-over-window'),
4
- 'prefer-txml-over-domparser': require('./rules/prefer-txml-over-domparser'),
5
- },
6
- };
@@ -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
- };