@onecx/angular-linter-rules 8.0.0-rc.1 → 8.0.0-rc.12

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.
Files changed (49) hide show
  1. package/README.md +0 -1
  2. package/package.json +6 -2
  3. package/src/index.d.ts +18 -0
  4. package/src/index.js +12 -0
  5. package/src/index.js.map +1 -0
  6. package/src/lib/configs.d.ts +2 -0
  7. package/src/lib/configs.js +16 -0
  8. package/src/lib/configs.js.map +1 -0
  9. package/src/lib/rules/index.d.ts +11 -0
  10. package/src/lib/rules/index.js +12 -0
  11. package/src/lib/rules/index.js.map +1 -0
  12. package/src/lib/rules/no-subscribe-assignment.rule.d.ts +4 -0
  13. package/src/lib/rules/no-subscribe-assignment.rule.js +132 -0
  14. package/src/lib/rules/no-subscribe-assignment.rule.js.map +1 -0
  15. package/src/lib/rules/no-translate-instant.rule.d.ts +4 -0
  16. package/src/lib/rules/no-translate-instant.rule.js +82 -0
  17. package/src/lib/rules/no-translate-instant.rule.js.map +1 -0
  18. package/src/lib/rules/prefer-translate-params.rule.d.ts +4 -0
  19. package/src/lib/rules/prefer-translate-params.rule.js +128 -0
  20. package/src/lib/rules/prefer-translate-params.rule.js.map +1 -0
  21. package/src/lib/types.d.ts +5 -0
  22. package/src/lib/types.js +3 -0
  23. package/src/lib/types.js.map +1 -0
  24. package/src/lib/utils/type-utils.d.ts +2 -0
  25. package/src/lib/utils/type-utils.js +17 -0
  26. package/src/lib/utils/type-utils.js.map +1 -0
  27. package/src/version.d.ts +2 -0
  28. package/src/version.js +6 -0
  29. package/src/version.js.map +1 -0
  30. package/eslint.config.cjs +0 -19
  31. package/jest.config.ts +0 -10
  32. package/project.json +0 -28
  33. package/src/index.ts +0 -11
  34. package/src/lib/configs.ts +0 -16
  35. package/src/lib/rules/index.ts +0 -9
  36. package/src/lib/rules/no-subscribe-assignment.rule.spec.ts +0 -118
  37. package/src/lib/rules/no-subscribe-assignment.rule.ts +0 -149
  38. package/src/lib/rules/no-translate-instant.rule.spec.ts +0 -122
  39. package/src/lib/rules/no-translate-instant.rule.ts +0 -98
  40. package/src/lib/rules/prefer-translate-params.rule.spec.ts +0 -97
  41. package/src/lib/rules/prefer-translate-params.rule.ts +0 -133
  42. package/src/lib/types.ts +0 -6
  43. package/src/lib/utils/type-utils.ts +0 -15
  44. package/src/types/rule-tester.d.ts +0 -3
  45. package/src/version.ts +0 -2
  46. package/tsconfig.json +0 -23
  47. package/tsconfig.lib.json +0 -10
  48. package/tsconfig.rule-tester.json +0 -5
  49. package/tsconfig.spec.json +0 -10
@@ -1,133 +0,0 @@
1
- import { AST_NODE_TYPES, ESLintUtils, TSESLint, TSESTree } from '@typescript-eslint/utils'
2
-
3
- const createRule = ESLintUtils.RuleCreator(
4
- (name) => `https://github.com/onecx/onecx-portal-ui-libs/tree/main/libs/angular-linter-rules#${name}`,
5
- )
6
-
7
- type Options = []
8
- type MessageIds = 'preferTranslateParams'
9
-
10
- const defaultAllowedFilePatterns = [/\.spec\.ts$/i, /\.test\.ts$/i, /\/testing\//i, /\/mocks\//i]
11
-
12
- function isAllowedTestFile(filename: string): boolean {
13
- if (!filename || filename === '<input>' || filename === '<text>') return false
14
- return defaultAllowedFilePatterns.some((re) => re.test(filename))
15
- }
16
-
17
- function isTranslateGetOrStreamCallExpression(node: TSESTree.Node): node is TSESTree.CallExpression {
18
- if (node.type !== AST_NODE_TYPES.CallExpression) return false
19
- if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return false
20
- if (node.callee.property.type !== AST_NODE_TYPES.Identifier) return false
21
- return node.callee.property.name === 'get' || node.callee.property.name === 'stream'
22
- }
23
-
24
- function isTranslateInstantCallExpression(node: TSESTree.Node): node is TSESTree.CallExpression {
25
- if (node.type !== AST_NODE_TYPES.CallExpression) return false
26
- if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return false
27
- if (node.callee.property.type !== AST_NODE_TYPES.Identifier) return false
28
- return node.callee.property.name === 'instant'
29
- }
30
-
31
- function isTranslateGetOrStreamPipeCallExpression(node: TSESTree.Node): node is TSESTree.CallExpression {
32
- if (node.type !== AST_NODE_TYPES.CallExpression) return false
33
- if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return false
34
- if (node.callee.property.type !== AST_NODE_TYPES.Identifier) return false
35
- if (node.callee.property.name !== 'pipe') return false
36
-
37
- const obj = node.callee.object
38
- return isTranslateGetOrStreamCallExpression(obj)
39
- }
40
-
41
- function containsBinaryPlus(context: TSESLint.RuleContext<MessageIds, Options>, node: TSESTree.Node): boolean {
42
- let found = false
43
-
44
- const visit = (n: TSESTree.Node): void => {
45
- if (found) return
46
-
47
- if (n.type === AST_NODE_TYPES.BinaryExpression && n.operator === '+') {
48
- found = true
49
- return
50
- }
51
-
52
- const keys = context.sourceCode.visitorKeys[n.type] ?? []
53
- for (const key of keys) {
54
- const value = (n as unknown as Record<string, unknown>)[key]
55
- if (!value) continue
56
-
57
- if (Array.isArray(value)) {
58
- for (const child of value) {
59
- if (found) return
60
- if (child && typeof child === 'object' && 'type' in (child as Record<string, unknown>)) {
61
- visit(child as TSESTree.Node)
62
- }
63
- }
64
- continue
65
- }
66
-
67
- if (value && typeof value === 'object' && 'type' in (value as Record<string, unknown>)) {
68
- visit(value as TSESTree.Node)
69
- }
70
- }
71
- }
72
-
73
- visit(node)
74
- return found
75
- }
76
-
77
- function isTranslatePipeExpression(node: TSESTree.Expression): boolean {
78
- if (node.type !== AST_NODE_TYPES.BinaryExpression || node.operator !== '|') return false
79
- const right = node.right
80
- return right.type === AST_NODE_TYPES.Identifier && right.name === 'translate'
81
- }
82
-
83
- export const preferTranslateParams = createRule<Options, MessageIds>({
84
- name: 'prefer-translate-params',
85
- meta: {
86
- type: 'suggestion',
87
- docs: {
88
- description:
89
- 'Prefer translation parameters instead of concatenating translated strings (use e.g. `translate.get(key, { param })`).',
90
- },
91
- schema: [],
92
- messages: {
93
- preferTranslateParams:
94
- 'Avoid concatenating translated strings. Prefer translation parameters/placeholders instead (e.g. `translate.get(key, { value })`).',
95
- },
96
- },
97
- defaultOptions: [],
98
- create(context) {
99
- const filename = context.filename
100
- const allowed = isAllowedTestFile(filename)
101
-
102
- if (allowed) {
103
- return {}
104
- }
105
-
106
- return {
107
- BinaryExpression(node) {
108
- if (node.operator !== '+') return
109
- if (
110
- isTranslateGetOrStreamCallExpression(node.left) ||
111
- isTranslateGetOrStreamCallExpression(node.right) ||
112
- isTranslateInstantCallExpression(node.left) ||
113
- isTranslateInstantCallExpression(node.right) ||
114
- isTranslatePipeExpression(node.left) ||
115
- isTranslatePipeExpression(node.right)
116
- ) {
117
- context.report({ node, messageId: 'preferTranslateParams' })
118
- }
119
- },
120
- TemplateLiteral(node) {
121
- if (!node.expressions.some((expr) => isTranslateGetOrStreamCallExpression(expr) || isTranslateInstantCallExpression(expr))) {
122
- return
123
- }
124
- context.report({ node, messageId: 'preferTranslateParams' })
125
- },
126
- CallExpression(node) {
127
- if (!isTranslateGetOrStreamPipeCallExpression(node)) return
128
- if (!containsBinaryPlus(context, node)) return
129
- context.report({ node, messageId: 'preferTranslateParams' })
130
- },
131
- }
132
- },
133
- })
package/src/lib/types.ts DELETED
@@ -1,6 +0,0 @@
1
- import type { TSESLint } from '@typescript-eslint/utils'
2
-
3
- export type AngularLinterRulesPlugin = {
4
- rules: Record<string, TSESLint.RuleModule<string, readonly unknown[]>>
5
- configs: Record<string, TSESLint.Linter.Config>
6
- }
@@ -1,15 +0,0 @@
1
- import type ts from 'typescript'
2
-
3
- export function isTranslateServiceType(typeChecker: ts.TypeChecker, type: ts.Type): boolean {
4
- const symbol = type.getSymbol() ?? type.aliasSymbol
5
- if (!symbol) return false
6
-
7
- const name = symbol.getName()
8
- if (name !== 'TranslateService') return false
9
-
10
- const declarations = symbol.getDeclarations() ?? []
11
- return declarations.some((decl) => {
12
- const sourceFileName = decl.getSourceFile().fileName
13
- return sourceFileName.includes('/@ngx-translate/core/') || sourceFileName.includes('\\@ngx-translate\\core\\')
14
- })
15
- }
@@ -1,3 +0,0 @@
1
- declare module '@typescript-eslint/rule-tester' {
2
- export * from '@typescript-eslint/rule-tester/dist/index'
3
- }
package/src/version.ts DELETED
@@ -1,2 +0,0 @@
1
- export const LIB_NAME = '@onecx/angular-linter-rules'
2
- export const LIB_VERSION = '0.0.0-PLACEHOLDER'
package/tsconfig.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "module": "commonjs",
5
- "forceConsistentCasingInFileNames": true,
6
- "strict": true,
7
- "importHelpers": true,
8
- "noImplicitOverride": true,
9
- "noImplicitReturns": true,
10
- "noFallthroughCasesInSwitch": true,
11
- "noPropertyAccessFromIndexSignature": true
12
- },
13
- "files": [],
14
- "include": [],
15
- "references": [
16
- {
17
- "path": "./tsconfig.lib.json"
18
- },
19
- {
20
- "path": "./tsconfig.spec.json"
21
- }
22
- ]
23
- }
package/tsconfig.lib.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../dist/out-tsc",
5
- "declaration": true,
6
- "types": ["node"]
7
- },
8
- "include": ["src/**/*.ts"],
9
- "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
10
- }
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "./tsconfig.spec.json",
3
- "include": ["src/**/*.ts", "src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.d.ts", "jest.config.ts"],
4
- "exclude": []
5
- }
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../dist/out-tsc",
5
- "module": "commonjs",
6
- "moduleResolution": "node10",
7
- "types": ["jest", "node"]
8
- },
9
- "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
10
- }