@swiftwc/eslint-plugin 1.1.2 → 1.1.4

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.
@@ -0,0 +1 @@
1
+ generated/
@@ -1,4 +1,4 @@
1
- import { RULES, swiftwc, validate } from '../index.js';
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 = RULES[tag];
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);
@@ -1,11 +1,11 @@
1
- import { RULES, swiftwc, validate } from '../index.js';
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 = RULES[tag];
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);
@@ -4,7 +4,7 @@ export type TagNode = {
4
4
  type: string;
5
5
  parent?: TagNode;
6
6
  };
7
- export declare const RULES: Record<string, string[]>;
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: {
@@ -1,20 +1,27 @@
1
1
  import { readFileSync } from 'fs';
2
- export const RULES = {
3
- 'v-keyboard': ['body'],
4
- 'scroll-view': ['body-view', 'dialog', 'navigation-stack', 'navigation-split-view', 'detail-placeholder'],
5
- dialog: ['tab-view', 'template'],
2
+ export const DIRECT_PARENT_RULES = {
3
+ 'v-keyboard': ['template', 'body'],
4
+ 'scroll-view': ['template', 'body-view', 'dialog', 'navigation-stack', 'navigation-split-view', 'detail-placeholder'],
5
+ dialog: ['template', 'tab-view', 'navigation-split-view'],
6
+ 'tool-bar': ['template', 'dialog', 'body-view', 'navigation-split-view', 'navigation-stack'],
7
+ 'tool-bar-item': ['template', 'tool-bar', 'tool-bar-item-group', 'sidebar-toggle'],
8
+ 'sidebar-toggle': ['template', 'tab-view', 'form', 'navigation-split-view'],
9
+ 'body-view': ['template', 'dialog', 'body-view', 'navigation-stack', 'navigation-split-view'],
6
10
  };
7
11
  export function validate(tag, getParentTag, allowedParents, context, node) {
8
- let parentTag = getParentTag(node), isValid = false;
9
- while (parentTag) {
10
- if (parentTag.type === node.type && allowedParents.includes(parentTag.name)) {
11
- isValid = true;
12
- break;
13
- }
14
- parentTag = getParentTag(parentTag);
15
- }
16
- if (isValid)
12
+ const parentTag = getParentTag(node);
13
+ if (parentTag?.type === node.type && allowedParents.includes(parentTag.name))
17
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
18
25
  context.report({
19
26
  // @ts-expect-error
20
27
  node,
@@ -82,7 +89,7 @@ export const swiftwc = {
82
89
  return {
83
90
  Tag(node) {
84
91
  const tag = node.name;
85
- const allowedParents = RULES[tag];
92
+ const allowedParents = DIRECT_PARENT_RULES[tag];
86
93
  if (!allowedParents)
87
94
  return; // 👈 ignore unknown tags completely
88
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.2",
3
+ "version": "1.1.4",
4
4
  "description": "Rules enforcing best practices while using SwiftWC.",
5
5
  "keywords": [
6
6
  "eslint",
@@ -32,8 +32,8 @@
32
32
  "scripts": {
33
33
  "prebuild": "rm -rf generated",
34
34
  "build": "npm run build:ts",
35
- "build:ts:watch": "npm run prebuild && tsc --watch",
36
35
  "build:ts": "tsc",
36
+ "start": "npm run prebuild && tsc --watch",
37
37
  "format:check": "prettier . --check",
38
38
  "format:write": "prettier . --write"
39
39
  },
package/src/emberjs/en.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { RuleContext, RuleListener } from '@typescript-eslint/utils/ts-eslint'
2
- import { RULES, swiftwc, validate, type TagNode } from '../index.js'
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 = RULES[tag]
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 { RULES, swiftwc, validate, type TagNode } from '../index.js'
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 = RULES[tag]
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,12 +7,20 @@ export type TagNode = {
7
7
  parent?: TagNode
8
8
  }
9
9
 
10
- export const RULES: Record<string, string[]> = {
11
- 'v-keyboard': ['body'],
10
+ export const DIRECT_PARENT_RULES: Record<string, string[]> = {
11
+ 'v-keyboard': ['template', 'body'],
12
12
 
13
- 'scroll-view': ['body-view', 'dialog', 'navigation-stack', 'navigation-split-view', 'detail-placeholder'],
13
+ 'scroll-view': ['template', 'body-view', 'dialog', 'navigation-stack', 'navigation-split-view', 'detail-placeholder'],
14
14
 
15
- dialog: ['tab-view', 'template'],
15
+ dialog: ['template', 'tab-view', 'navigation-split-view'],
16
+
17
+ 'tool-bar': ['template', 'dialog', 'body-view', 'navigation-split-view', 'navigation-stack'],
18
+
19
+ 'tool-bar-item': ['template', 'tool-bar', 'tool-bar-item-group', 'sidebar-toggle'],
20
+
21
+ 'sidebar-toggle': ['template', 'tab-view', 'form', 'navigation-split-view'],
22
+
23
+ 'body-view': ['template', 'dialog', 'body-view', 'navigation-stack', 'navigation-split-view'],
16
24
  }
17
25
 
18
26
  export function validate(
@@ -22,19 +30,21 @@ export function validate(
22
30
  context: RuleContext<string, readonly unknown[]>,
23
31
  node: TagNode
24
32
  ) {
25
- let parentTag = getParentTag(node),
26
- isValid = false
33
+ const parentTag = getParentTag(node)
27
34
 
28
- while (parentTag) {
29
- if (parentTag.type === node.type && allowedParents.includes(parentTag.name)) {
30
- isValid = true
31
- break
32
- }
35
+ if (parentTag?.type === node.type && allowedParents.includes(parentTag.name)) return
33
36
 
34
- parentTag = getParentTag(parentTag)
35
- }
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
+ // }
36
46
 
37
- if (isValid) return
47
+ // if (isValid) return
38
48
 
39
49
  context.report({
40
50
  // @ts-expect-error
@@ -109,7 +119,7 @@ export const swiftwc = {
109
119
  Tag(node: TagNode) {
110
120
  const tag = node.name
111
121
 
112
- const allowedParents = RULES[tag]
122
+ const allowedParents = DIRECT_PARENT_RULES[tag]
113
123
  if (!allowedParents) return // 👈 ignore unknown tags completely
114
124
 
115
125
  validate(tag, (item) => item.parent, allowedParents, context, node)
package/tsconfig.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
- "extends": "../../tsconfig.base.json",
2
+ "extends": "../../.config/tsconfig.base.json",
3
3
  "compilerOptions": {
4
4
  "outDir": "generated",
5
5
  "rootDir": "src",
6
6
  "skipLibCheck": true,
7
7
  "module": "NodeNext",
8
8
  "moduleResolution": "NodeNext",
9
- "resolveJsonModule": true
9
+ "resolveJsonModule": true,
10
+ "types": ["node"]
10
11
  },
11
12
  "include": ["src"],
12
13
  "exclude": ["**/*.test.ts"]