@swiftwc/eslint-plugin 1.1.3 → 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,22 +1,27 @@
1
1
  import { readFileSync } from 'fs';
2
- export const RULES = {
2
+ export const DIRECT_PARENT_RULES = {
3
3
  'v-keyboard': ['template', 'body'],
4
4
  'scroll-view': ['template', 'body-view', 'dialog', 'navigation-stack', 'navigation-split-view', 'detail-placeholder'],
5
5
  dialog: ['template', 'tab-view', 'navigation-split-view'],
6
- 'tool-bar': ['template', 'body-view', 'navigation-split-view', 'navigation-stack'],
6
+ 'tool-bar': ['template', 'dialog', 'body-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'],
9
+ 'body-view': ['template', 'dialog', 'body-view', 'navigation-stack', 'navigation-split-view'],
8
10
  };
9
11
  export function validate(tag, getParentTag, allowedParents, context, node) {
10
- let parentTag = getParentTag(node), isValid = false;
11
- while (parentTag) {
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 = RULES[tag];
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",
3
+ "version": "1.1.4",
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 format:write && npm run build:ts",
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 { 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,16 +7,20 @@ export type TagNode = {
7
7
  parent?: TagNode
8
8
  }
9
9
 
10
- export const RULES: Record<string, string[]> = {
10
+ export const DIRECT_PARENT_RULES: Record<string, string[]> = {
11
11
  'v-keyboard': ['template', 'body'],
12
12
 
13
13
  'scroll-view': ['template', 'body-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', 'body-view', 'navigation-split-view', 'navigation-stack'],
17
+ 'tool-bar': ['template', 'dialog', 'body-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'],
22
+
23
+ 'body-view': ['template', 'dialog', 'body-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
- let parentTag = getParentTag(node),
30
- isValid = false
33
+ const parentTag = getParentTag(node)
31
34
 
32
- while (parentTag) {
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
- parentTag = getParentTag(parentTag)
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 = RULES[tag]
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)
package/tsconfig.json CHANGED
@@ -6,7 +6,8 @@
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"]