@swiftwc/eslint-plugin 1.1.3 → 1.1.5
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/.prettierignore +1 -0
- package/generated/emberjs/en.js +2 -2
- package/generated/html/en.js +2 -2
- package/generated/index.d.ts +1 -1
- package/generated/index.js +18 -13
- package/package.json +2 -2
- package/src/emberjs/en.ts +2 -2
- package/src/html/en.ts +2 -2
- package/src/index.ts +20 -14
- package/tsconfig.json +2 -1
package/.prettierignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
generated/
|
package/generated/emberjs/en.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DIRECT_PARENT_RULES, swiftwc, validate } from '../index.js';
|
|
2
2
|
swiftwc.rules['allowed-tags'].meta.docs.description = 'Restrict allowed HTML tags';
|
|
3
3
|
swiftwc.rules['allowed-tags'].meta.messages.disallowedTag = 'Tag <{{tag}}> is only allowed inside any of: {{allowed}}';
|
|
4
4
|
swiftwc.rules['allowed-tags'].create = (context) => {
|
|
@@ -8,7 +8,7 @@ swiftwc.rules['allowed-tags'].create = (context) => {
|
|
|
8
8
|
GlimmerElementNode(node) {
|
|
9
9
|
// @ts-expect-error
|
|
10
10
|
const tag = node.tag;
|
|
11
|
-
const allowedParents =
|
|
11
|
+
const allowedParents = DIRECT_PARENT_RULES[tag];
|
|
12
12
|
if (!allowedParents)
|
|
13
13
|
return; // 👈 ignore unknown tags completely
|
|
14
14
|
validate(tag, (item) => item.parent, allowedParents, context, node);
|
package/generated/html/en.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DIRECT_PARENT_RULES, swiftwc, validate } from '../index.js';
|
|
2
2
|
swiftwc.rules['allowed-tags'].meta.docs.description = 'Restrict allowed HTML tags';
|
|
3
3
|
swiftwc.rules['allowed-tags'].meta.messages.disallowedTag = 'Tag <{{tag}}> is only allowed inside any of: {{allowed}}';
|
|
4
4
|
swiftwc.rules['allowed-tags'].create = (context) => {
|
|
5
5
|
return {
|
|
6
6
|
Tag(node) {
|
|
7
7
|
const tag = node.name;
|
|
8
|
-
const allowedParents =
|
|
8
|
+
const allowedParents = DIRECT_PARENT_RULES[tag];
|
|
9
9
|
if (!allowedParents)
|
|
10
10
|
return; // 👈 ignore unknown tags completely
|
|
11
11
|
validate(tag, (item) => item.parent, allowedParents, context, node);
|
package/generated/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type TagNode = {
|
|
|
4
4
|
type: string;
|
|
5
5
|
parent?: TagNode;
|
|
6
6
|
};
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const DIRECT_PARENT_RULES: Record<string, string[]>;
|
|
8
8
|
export declare function validate(tag: string, getParentTag: (node: TagNode) => TagNode | undefined, allowedParents: string[], context: RuleContext<string, readonly unknown[]>, node: TagNode): void;
|
|
9
9
|
export declare const swiftwc: {
|
|
10
10
|
meta: {
|
package/generated/index.js
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
import { readFileSync } from 'fs';
|
|
2
|
-
export const
|
|
2
|
+
export const DIRECT_PARENT_RULES = {
|
|
3
3
|
'v-keyboard': ['template', 'body'],
|
|
4
|
-
'scroll-view': ['template', '
|
|
4
|
+
'scroll-view': ['template', 'content-view', 'dialog', 'navigation-stack', 'navigation-split-view', 'detail-placeholder'],
|
|
5
5
|
dialog: ['template', 'tab-view', 'navigation-split-view'],
|
|
6
|
-
'tool-bar': ['template', '
|
|
6
|
+
'tool-bar': ['template', 'dialog', 'content-view', 'navigation-split-view', 'navigation-stack'],
|
|
7
7
|
'tool-bar-item': ['template', 'tool-bar', 'tool-bar-item-group', 'sidebar-toggle'],
|
|
8
|
+
'sidebar-toggle': ['template', 'tab-view', 'form', 'navigation-split-view', 'tool-bar'],
|
|
9
|
+
'content-view': ['template', 'dialog', 'content-view', 'navigation-stack', 'navigation-split-view'],
|
|
8
10
|
};
|
|
9
11
|
export function validate(tag, getParentTag, allowedParents, context, node) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (parentTag.type === node.type && allowedParents.includes(parentTag.name)) {
|
|
13
|
-
isValid = true;
|
|
14
|
-
break;
|
|
15
|
-
}
|
|
16
|
-
parentTag = getParentTag(parentTag);
|
|
17
|
-
}
|
|
18
|
-
if (isValid)
|
|
12
|
+
const parentTag = getParentTag(node);
|
|
13
|
+
if (parentTag?.type === node.type && allowedParents.includes(parentTag.name))
|
|
19
14
|
return;
|
|
15
|
+
// let parentTag = getParentTag(node),
|
|
16
|
+
// isValid = false
|
|
17
|
+
// while (parentTag) {
|
|
18
|
+
// if (parentTag.type === node.type && allowedParents.includes(parentTag.name)) {
|
|
19
|
+
// isValid = true
|
|
20
|
+
// break
|
|
21
|
+
// }
|
|
22
|
+
// parentTag = getParentTag(parentTag)
|
|
23
|
+
// }
|
|
24
|
+
// if (isValid) return
|
|
20
25
|
context.report({
|
|
21
26
|
// @ts-expect-error
|
|
22
27
|
node,
|
|
@@ -84,7 +89,7 @@ export const swiftwc = {
|
|
|
84
89
|
return {
|
|
85
90
|
Tag(node) {
|
|
86
91
|
const tag = node.name;
|
|
87
|
-
const allowedParents =
|
|
92
|
+
const allowedParents = DIRECT_PARENT_RULES[tag];
|
|
88
93
|
if (!allowedParents)
|
|
89
94
|
return; // 👈 ignore unknown tags completely
|
|
90
95
|
validate(tag, (item) => item.parent, allowedParents, context, node);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swiftwc/eslint-plugin",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "Rules enforcing best practices while using SwiftWC.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"prebuild": "rm -rf generated",
|
|
34
|
-
"build": "npm run
|
|
34
|
+
"build": "npm run build:ts",
|
|
35
35
|
"build:ts": "tsc",
|
|
36
36
|
"start": "npm run prebuild && tsc --watch",
|
|
37
37
|
"format:check": "prettier . --check",
|
package/src/emberjs/en.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RuleContext, RuleListener } from '@typescript-eslint/utils/ts-eslint'
|
|
2
|
-
import {
|
|
2
|
+
import { DIRECT_PARENT_RULES, swiftwc, validate, type TagNode } from '../index.js'
|
|
3
3
|
|
|
4
4
|
swiftwc.rules['allowed-tags'].meta.docs.description = 'Restrict allowed HTML tags'
|
|
5
5
|
|
|
@@ -13,7 +13,7 @@ swiftwc.rules['allowed-tags'].create = (context: Readonly<RuleContext<string, re
|
|
|
13
13
|
// @ts-expect-error
|
|
14
14
|
const tag = node.tag
|
|
15
15
|
|
|
16
|
-
const allowedParents =
|
|
16
|
+
const allowedParents = DIRECT_PARENT_RULES[tag]
|
|
17
17
|
if (!allowedParents) return // 👈 ignore unknown tags completely
|
|
18
18
|
|
|
19
19
|
validate(tag, (item) => item.parent, allowedParents, context, node)
|
package/src/html/en.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RuleContext, RuleListener } from '@typescript-eslint/utils/ts-eslint'
|
|
2
|
-
import {
|
|
2
|
+
import { DIRECT_PARENT_RULES, swiftwc, validate, type TagNode } from '../index.js'
|
|
3
3
|
|
|
4
4
|
swiftwc.rules['allowed-tags'].meta.docs.description = 'Restrict allowed HTML tags'
|
|
5
5
|
|
|
@@ -10,7 +10,7 @@ swiftwc.rules['allowed-tags'].create = (context: Readonly<RuleContext<string, re
|
|
|
10
10
|
Tag(node: TagNode) {
|
|
11
11
|
const tag = node.name
|
|
12
12
|
|
|
13
|
-
const allowedParents =
|
|
13
|
+
const allowedParents = DIRECT_PARENT_RULES[tag]
|
|
14
14
|
if (!allowedParents) return // 👈 ignore unknown tags completely
|
|
15
15
|
|
|
16
16
|
validate(tag, (item) => item.parent, allowedParents, context, node)
|
package/src/index.ts
CHANGED
|
@@ -7,16 +7,20 @@ export type TagNode = {
|
|
|
7
7
|
parent?: TagNode
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export const
|
|
10
|
+
export const DIRECT_PARENT_RULES: Record<string, string[]> = {
|
|
11
11
|
'v-keyboard': ['template', 'body'],
|
|
12
12
|
|
|
13
|
-
'scroll-view': ['template', '
|
|
13
|
+
'scroll-view': ['template', 'content-view', 'dialog', 'navigation-stack', 'navigation-split-view', 'detail-placeholder'],
|
|
14
14
|
|
|
15
15
|
dialog: ['template', 'tab-view', 'navigation-split-view'],
|
|
16
16
|
|
|
17
|
-
'tool-bar': ['template', '
|
|
17
|
+
'tool-bar': ['template', 'dialog', 'content-view', 'navigation-split-view', 'navigation-stack'],
|
|
18
18
|
|
|
19
19
|
'tool-bar-item': ['template', 'tool-bar', 'tool-bar-item-group', 'sidebar-toggle'],
|
|
20
|
+
|
|
21
|
+
'sidebar-toggle': ['template', 'tab-view', 'form', 'navigation-split-view', 'tool-bar'],
|
|
22
|
+
|
|
23
|
+
'content-view': ['template', 'dialog', 'content-view', 'navigation-stack', 'navigation-split-view'],
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
export function validate(
|
|
@@ -26,19 +30,21 @@ export function validate(
|
|
|
26
30
|
context: RuleContext<string, readonly unknown[]>,
|
|
27
31
|
node: TagNode
|
|
28
32
|
) {
|
|
29
|
-
|
|
30
|
-
isValid = false
|
|
33
|
+
const parentTag = getParentTag(node)
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
if (parentTag.type === node.type && allowedParents.includes(parentTag.name)) {
|
|
34
|
-
isValid = true
|
|
35
|
-
break
|
|
36
|
-
}
|
|
35
|
+
if (parentTag?.type === node.type && allowedParents.includes(parentTag.name)) return
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
// let parentTag = getParentTag(node),
|
|
38
|
+
// isValid = false
|
|
39
|
+
// while (parentTag) {
|
|
40
|
+
// if (parentTag.type === node.type && allowedParents.includes(parentTag.name)) {
|
|
41
|
+
// isValid = true
|
|
42
|
+
// break
|
|
43
|
+
// }
|
|
44
|
+
// parentTag = getParentTag(parentTag)
|
|
45
|
+
// }
|
|
40
46
|
|
|
41
|
-
if (isValid) return
|
|
47
|
+
// if (isValid) return
|
|
42
48
|
|
|
43
49
|
context.report({
|
|
44
50
|
// @ts-expect-error
|
|
@@ -113,7 +119,7 @@ export const swiftwc = {
|
|
|
113
119
|
Tag(node: TagNode) {
|
|
114
120
|
const tag = node.name
|
|
115
121
|
|
|
116
|
-
const allowedParents =
|
|
122
|
+
const allowedParents = DIRECT_PARENT_RULES[tag]
|
|
117
123
|
if (!allowedParents) return // 👈 ignore unknown tags completely
|
|
118
124
|
|
|
119
125
|
validate(tag, (item) => item.parent, allowedParents, context, node)
|