@tamagui/eslint-plugin 0.0.0-bootstrap.0 → 3.0.0-beta.1097.1

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/src/index.ts ADDED
@@ -0,0 +1,125 @@
1
+ import type { Rule } from 'eslint'
2
+ import {
3
+ extractStyleSitesFromEstree,
4
+ type EstreeStyleSite,
5
+ } from '@tamagui/language-service/extract-estree'
6
+ import {
7
+ canonicalizeStyleValue,
8
+ createCandidatePropertyVocabulary,
9
+ createModifierRegistry,
10
+ createStylePropSet,
11
+ diagnoseStyleValueProgram,
12
+ type GrammarConfigView,
13
+ } from '@tamagui/style-grammar/tooling'
14
+
15
+ type RuleOption = {
16
+ config: GrammarConfigView
17
+ strictPayloads?: boolean
18
+ }
19
+
20
+ export const validFlatValues: Rule.RuleModule = {
21
+ meta: {
22
+ type: 'problem',
23
+ fixable: 'code',
24
+ docs: {
25
+ description: 'validate static Tamagui flat values with @tamagui/style-grammar',
26
+ },
27
+ schema: [
28
+ {
29
+ type: 'object',
30
+ properties: {
31
+ config: {
32
+ type: 'object',
33
+ },
34
+ strictPayloads: {
35
+ type: 'boolean',
36
+ },
37
+ },
38
+ required: ['config'],
39
+ additionalProperties: false,
40
+ },
41
+ ],
42
+ messages: {
43
+ invalidFlatValue: '{{message}}',
44
+ nonCanonicalFlatValue: 'use the canonical flat value "{{canonical}}"',
45
+ },
46
+ },
47
+
48
+ create(context) {
49
+ const option = context.options[0] as RuleOption | undefined
50
+ const config = option?.config || {}
51
+ const strictPayloads = option?.strictPayloads ?? false
52
+ const registry = createModifierRegistry(config).registry
53
+ const candidates = createCandidatePropertyVocabulary(config)
54
+ const styleProps = createStylePropSet(config)
55
+ const sourceCode = context.sourceCode
56
+
57
+ const report = (site: EstreeStyleSite): void => {
58
+ const node = site.node as Rule.Node
59
+ const diagnostics = diagnoseStyleValueProgram(site.property, site.value, {
60
+ config,
61
+ registry,
62
+ candidates,
63
+ strictPayloads,
64
+ })
65
+ for (const diagnostic of diagnostics) {
66
+ context.report({
67
+ node,
68
+ // the engine reports value-relative spans; surface them exactly
69
+ loc: {
70
+ start: sourceCode.getLocFromIndex(site.start + diagnostic.start),
71
+ end: sourceCode.getLocFromIndex(site.start + diagnostic.end),
72
+ },
73
+ messageId: 'invalidFlatValue',
74
+ data: { message: diagnostic.message },
75
+ })
76
+ }
77
+ if (diagnostics.length > 0) return
78
+
79
+ const formatted = canonicalizeStyleValue(site.value, registry)
80
+ if (!formatted.ok || formatted.value === site.value) return
81
+ const canonical = formatted.value
82
+ context.report({
83
+ node,
84
+ messageId: 'nonCanonicalFlatValue',
85
+ data: { canonical },
86
+ fix(fixer) {
87
+ return fixer.replaceText(node, JSON.stringify(canonical))
88
+ },
89
+ })
90
+ }
91
+
92
+ return {
93
+ 'Program:exit'(program) {
94
+ const sites = extractStyleSitesFromEstree(program, {
95
+ isStyleProp: (name) => styleProps.has(name),
96
+ })
97
+ for (const site of sites) report(site)
98
+ },
99
+ }
100
+ },
101
+ }
102
+
103
+ export interface TamaguiEslintRules {
104
+ 'valid-flat-values': Rule.RuleModule
105
+ }
106
+
107
+ export interface TamaguiEslintPlugin {
108
+ meta: {
109
+ name: string
110
+ }
111
+ rules: TamaguiEslintRules
112
+ }
113
+
114
+ export const rules: TamaguiEslintRules = {
115
+ 'valid-flat-values': validFlatValues,
116
+ }
117
+
118
+ const plugin: TamaguiEslintPlugin = {
119
+ meta: {
120
+ name: '@tamagui/eslint-plugin',
121
+ },
122
+ rules,
123
+ }
124
+
125
+ export default plugin
@@ -0,0 +1,95 @@
1
+ import {
2
+ extractStyleSitesFromEstree,
3
+ type EstreeStyleSite,
4
+ } from '@tamagui/language-service/extract-estree'
5
+ import {
6
+ canonicalizeStyleValue,
7
+ createCandidatePropertyVocabulary,
8
+ createModifierRegistry,
9
+ createStylePropSet,
10
+ diagnoseStyleValueProgram,
11
+ type GrammarConfigView,
12
+ } from '@tamagui/style-grammar/tooling'
13
+ import type { Rule } from 'eslint'
14
+
15
+ type RuleOption = {
16
+ config: GrammarConfigView
17
+ }
18
+
19
+ export const validFlatValues: Rule.RuleModule = {
20
+ meta: {
21
+ type: 'problem',
22
+ fixable: 'code',
23
+ docs: {
24
+ description: 'validate static Tamagui flat values with @tamagui/style-grammar',
25
+ },
26
+ schema: [
27
+ {
28
+ type: 'object',
29
+ properties: {
30
+ config: {
31
+ type: 'object',
32
+ },
33
+ },
34
+ required: ['config'],
35
+ additionalProperties: false,
36
+ },
37
+ ],
38
+ messages: {
39
+ invalidFlatValue: '{{message}}',
40
+ nonCanonicalFlatValue: 'use the canonical flat value "{{canonical}}"',
41
+ },
42
+ },
43
+
44
+ create(context) {
45
+ const option = context.options[0] as RuleOption | undefined
46
+ const config = option?.config || {}
47
+ const registry = createModifierRegistry(config).registry
48
+ const candidates = createCandidatePropertyVocabulary(config)
49
+ const styleProps = createStylePropSet(config)
50
+ const sourceCode = context.sourceCode
51
+
52
+ const report = (site: EstreeStyleSite): void => {
53
+ const node = site.node as Rule.Node
54
+ const diagnostics = diagnoseStyleValueProgram(site.property, site.value, {
55
+ config,
56
+ registry,
57
+ candidates,
58
+ })
59
+ for (const diagnostic of diagnostics) {
60
+ context.report({
61
+ node,
62
+ // the engine reports value-relative spans; surface them exactly
63
+ loc: {
64
+ start: sourceCode.getLocFromIndex(site.start + diagnostic.start),
65
+ end: sourceCode.getLocFromIndex(site.start + diagnostic.end),
66
+ },
67
+ messageId: 'invalidFlatValue',
68
+ data: { message: diagnostic.message },
69
+ })
70
+ }
71
+ if (diagnostics.length > 0) return
72
+
73
+ const formatted = canonicalizeStyleValue(site.value, registry)
74
+ if (!formatted.ok || formatted.value === site.value) return
75
+ const canonical = formatted.value
76
+ context.report({
77
+ node,
78
+ messageId: 'nonCanonicalFlatValue',
79
+ data: { canonical },
80
+ fix(fixer) {
81
+ return fixer.replaceText(node, JSON.stringify(canonical))
82
+ },
83
+ })
84
+ }
85
+
86
+ return {
87
+ 'Program:exit'(program) {
88
+ const sites = extractStyleSitesFromEstree(program, {
89
+ isStyleProp: (name) => styleProps.has(name),
90
+ })
91
+ for (const site of sites) report(site)
92
+ },
93
+ }
94
+ },
95
+ }
@@ -0,0 +1,16 @@
1
+ import type { Rule } from "eslint";
2
+ export declare const validFlatValues: Rule.RuleModule;
3
+ export interface TamaguiEslintRules {
4
+ "valid-flat-values": Rule.RuleModule;
5
+ }
6
+ export interface TamaguiEslintPlugin {
7
+ meta: {
8
+ name: string;
9
+ };
10
+ rules: TamaguiEslintRules;
11
+ }
12
+ export declare const rules: TamaguiEslintRules;
13
+ declare const plugin: TamaguiEslintPlugin;
14
+ export default plugin;
15
+
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "mappings": "AAAA,cAAc,YAAY;AAmB1B,OAAO,cAAM,iBAAiB,KAAK;AAmFnC,iBAAiB,mBAAmB;CAClC,qBAAqB,KAAK;;AAG5B,iBAAiB,oBAAoB;CACnC,MAAM;EACJ;;CAEF,OAAO;;AAGT,OAAO,cAAM,OAAO;AAIpB,cAAM,QAAQ;AAOd,eAAe",
3
+ "names": [],
4
+ "sources": [
5
+ "src/index.ts"
6
+ ],
7
+ "version": 3,
8
+ "sourcesContent": [
9
+ "import type { Rule } from 'eslint'\nimport {\n extractStyleSitesFromEstree,\n type EstreeStyleSite,\n} from '@tamagui/language-service/extract-estree'\nimport {\n canonicalizeStyleValue,\n createCandidatePropertyVocabulary,\n createModifierRegistry,\n createStylePropSet,\n diagnoseStyleValueProgram,\n type GrammarConfigView,\n} from '@tamagui/style-grammar/tooling'\n\ntype RuleOption = {\n config: GrammarConfigView\n strictPayloads?: boolean\n}\n\nexport const validFlatValues: Rule.RuleModule = {\n meta: {\n type: 'problem',\n fixable: 'code',\n docs: {\n description: 'validate static Tamagui flat values with @tamagui/style-grammar',\n },\n schema: [\n {\n type: 'object',\n properties: {\n config: {\n type: 'object',\n },\n strictPayloads: {\n type: 'boolean',\n },\n },\n required: ['config'],\n additionalProperties: false,\n },\n ],\n messages: {\n invalidFlatValue: '{{message}}',\n nonCanonicalFlatValue: 'use the canonical flat value \"{{canonical}}\"',\n },\n },\n\n create(context) {\n const option = context.options[0] as RuleOption | undefined\n const config = option?.config || {}\n const strictPayloads = option?.strictPayloads ?? false\n const registry = createModifierRegistry(config).registry\n const candidates = createCandidatePropertyVocabulary(config)\n const styleProps = createStylePropSet(config)\n const sourceCode = context.sourceCode\n\n const report = (site: EstreeStyleSite): void => {\n const node = site.node as Rule.Node\n const diagnostics = diagnoseStyleValueProgram(site.property, site.value, {\n config,\n registry,\n candidates,\n strictPayloads,\n })\n for (const diagnostic of diagnostics) {\n context.report({\n node,\n // the engine reports value-relative spans; surface them exactly\n loc: {\n start: sourceCode.getLocFromIndex(site.start + diagnostic.start),\n end: sourceCode.getLocFromIndex(site.start + diagnostic.end),\n },\n messageId: 'invalidFlatValue',\n data: { message: diagnostic.message },\n })\n }\n if (diagnostics.length > 0) return\n\n const formatted = canonicalizeStyleValue(site.value, registry)\n if (!formatted.ok || formatted.value === site.value) return\n const canonical = formatted.value\n context.report({\n node,\n messageId: 'nonCanonicalFlatValue',\n data: { canonical },\n fix(fixer) {\n return fixer.replaceText(node, JSON.stringify(canonical))\n },\n })\n }\n\n return {\n 'Program:exit'(program) {\n const sites = extractStyleSitesFromEstree(program, {\n isStyleProp: (name) => styleProps.has(name),\n })\n for (const site of sites) report(site)\n },\n }\n },\n}\n\nexport interface TamaguiEslintRules {\n 'valid-flat-values': Rule.RuleModule\n}\n\nexport interface TamaguiEslintPlugin {\n meta: {\n name: string\n }\n rules: TamaguiEslintRules\n}\n\nexport const rules: TamaguiEslintRules = {\n 'valid-flat-values': validFlatValues,\n}\n\nconst plugin: TamaguiEslintPlugin = {\n meta: {\n name: '@tamagui/eslint-plugin',\n },\n rules,\n}\n\nexport default plugin\n"
10
+ ]
11
+ }
@@ -0,0 +1,4 @@
1
+ import type { Rule } from "eslint";
2
+ export declare const validFlatValues: Rule.RuleModule;
3
+
4
+ //# sourceMappingURL=validFlatValues.d.ts.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "mappings": "AAYA,cAAc,YAAY;AAM1B,OAAO,cAAM,iBAAiB,KAAK",
3
+ "names": [],
4
+ "sources": [
5
+ "src/validFlatValues.ts"
6
+ ],
7
+ "version": 3,
8
+ "sourcesContent": [
9
+ "import {\n extractStyleSitesFromEstree,\n type EstreeStyleSite,\n} from '@tamagui/language-service/extract-estree'\nimport {\n canonicalizeStyleValue,\n createCandidatePropertyVocabulary,\n createModifierRegistry,\n createStylePropSet,\n diagnoseStyleValueProgram,\n type GrammarConfigView,\n} from '@tamagui/style-grammar/tooling'\nimport type { Rule } from 'eslint'\n\ntype RuleOption = {\n config: GrammarConfigView\n}\n\nexport const validFlatValues: Rule.RuleModule = {\n meta: {\n type: 'problem',\n fixable: 'code',\n docs: {\n description: 'validate static Tamagui flat values with @tamagui/style-grammar',\n },\n schema: [\n {\n type: 'object',\n properties: {\n config: {\n type: 'object',\n },\n },\n required: ['config'],\n additionalProperties: false,\n },\n ],\n messages: {\n invalidFlatValue: '{{message}}',\n nonCanonicalFlatValue: 'use the canonical flat value \"{{canonical}}\"',\n },\n },\n\n create(context) {\n const option = context.options[0] as RuleOption | undefined\n const config = option?.config || {}\n const registry = createModifierRegistry(config).registry\n const candidates = createCandidatePropertyVocabulary(config)\n const styleProps = createStylePropSet(config)\n const sourceCode = context.sourceCode\n\n const report = (site: EstreeStyleSite): void => {\n const node = site.node as Rule.Node\n const diagnostics = diagnoseStyleValueProgram(site.property, site.value, {\n config,\n registry,\n candidates,\n })\n for (const diagnostic of diagnostics) {\n context.report({\n node,\n // the engine reports value-relative spans; surface them exactly\n loc: {\n start: sourceCode.getLocFromIndex(site.start + diagnostic.start),\n end: sourceCode.getLocFromIndex(site.start + diagnostic.end),\n },\n messageId: 'invalidFlatValue',\n data: { message: diagnostic.message },\n })\n }\n if (diagnostics.length > 0) return\n\n const formatted = canonicalizeStyleValue(site.value, registry)\n if (!formatted.ok || formatted.value === site.value) return\n const canonical = formatted.value\n context.report({\n node,\n messageId: 'nonCanonicalFlatValue',\n data: { canonical },\n fix(fixer) {\n return fixer.replaceText(node, JSON.stringify(canonical))\n },\n })\n }\n\n return {\n 'Program:exit'(program) {\n const sites = extractStyleSitesFromEstree(program, {\n isStyleProp: (name) => styleProps.has(name),\n })\n for (const site of sites) report(site)\n },\n }\n },\n}\n"
10
+ ]
11
+ }