@atom63/eslint-plugin 0.0.0-stage → 0.1.0-beta.0

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,101 @@
1
+ import ts from 'typescript'
2
+
3
+ /**
4
+ * Warnings in one TSX file, for `<Button>` imported from `@atom63/*`:
5
+ * - `button-without-variant`: each one that passes no `variant` (and spreads no
6
+ * props that could carry one). It draws the `default` neutral solid, the
7
+ * heaviest neutral, which is rarely meant for a back, keypad or secondary
8
+ * action.
9
+ * - `multiple-primary`: one warning, at the second one, when more than one
10
+ * passes a literal `variant="primary"` (or `{'primary'}`). One main action
11
+ * per view is the rule; a computed variant is not counted.
12
+ * - `ghost-without-tone`: each one that passes a literal `variant="ghost"`
13
+ * and no `tone` (and spreads no props that could carry one). Secondary
14
+ * actions in toolbars, rows and card headers take `tone="muted"`.
15
+ * @returns {{ rule: 'button-without-variant' | 'multiple-primary' | 'ghost-without-tone', line: number, match: string }[]}
16
+ */
17
+ export function findWarnings(source, fileName = 'file.tsx') {
18
+ const file = ts.createSourceFile(
19
+ fileName,
20
+ source,
21
+ ts.ScriptTarget.Latest,
22
+ true,
23
+ ts.ScriptKind.TSX
24
+ )
25
+ const systemButtons = new Set()
26
+ for (const statement of file.statements) {
27
+ if (!ts.isImportDeclaration(statement) || !statement.importClause) continue
28
+ const from = /** @type {import('typescript').StringLiteral} */ (statement.moduleSpecifier).text
29
+ const bindings = statement.importClause.namedBindings
30
+ if (!from.startsWith('@atom63/') || !bindings || !ts.isNamedImports(bindings)) continue
31
+ for (const element of bindings.elements) {
32
+ if ((element.propertyName ?? element.name).text === 'Button')
33
+ systemButtons.add(element.name.text)
34
+ }
35
+ }
36
+ const warnings = []
37
+ const primaries = []
38
+ const literal = initializer => {
39
+ if (!initializer) return undefined
40
+ if (ts.isStringLiteral(initializer)) return initializer.text
41
+ if (ts.isJsxExpression(initializer) && initializer.expression) {
42
+ const expression = initializer.expression
43
+ if (ts.isStringLiteral(expression) || ts.isNoSubstitutionTemplateLiteral(expression))
44
+ return expression.text
45
+ }
46
+ return undefined
47
+ }
48
+ const visit = node => {
49
+ if (
50
+ (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) &&
51
+ systemButtons.has(node.tagName.getText(file))
52
+ ) {
53
+ const attributes = node.attributes.properties
54
+ const open = attributes.some(
55
+ attribute =>
56
+ ts.isJsxSpreadAttribute(attribute) ||
57
+ (ts.isJsxAttribute(attribute) && attribute.name.getText(file) === 'variant')
58
+ )
59
+ const { line } = file.getLineAndCharacterOfPosition(node.getStart(file))
60
+ if (!open) {
61
+ warnings.push({
62
+ rule: /** @type {const} */ ('button-without-variant'),
63
+ line: line + 1,
64
+ match: node.getText(file).split('\n')[0],
65
+ })
66
+ }
67
+ const variant = attributes.find(
68
+ attribute => ts.isJsxAttribute(attribute) && attribute.name.getText(file) === 'variant'
69
+ )
70
+ if (variant && ts.isJsxAttribute(variant) && literal(variant.initializer) === 'primary')
71
+ primaries.push({ line: line + 1, match: node.getText(file).split('\n')[0] })
72
+ const toned = attributes.some(
73
+ attribute =>
74
+ ts.isJsxSpreadAttribute(attribute) ||
75
+ (ts.isJsxAttribute(attribute) && attribute.name.getText(file) === 'tone')
76
+ )
77
+ if (
78
+ variant &&
79
+ ts.isJsxAttribute(variant) &&
80
+ literal(variant.initializer) === 'ghost' &&
81
+ !toned
82
+ ) {
83
+ warnings.push({
84
+ rule: /** @type {const} */ ('ghost-without-tone'),
85
+ line: line + 1,
86
+ match: node.getText(file).split('\n')[0],
87
+ })
88
+ }
89
+ }
90
+ ts.forEachChild(node, visit)
91
+ }
92
+ visit(file)
93
+ if (primaries.length > 1) {
94
+ warnings.push({
95
+ rule: /** @type {const} */ ('multiple-primary'),
96
+ line: primaries[1].line,
97
+ match: primaries[1].match,
98
+ })
99
+ }
100
+ return warnings
101
+ }
package/src/index.mjs ADDED
@@ -0,0 +1,90 @@
1
+ /**
2
+ * @atom63/eslint-plugin: rules that keep screen code on the Atom63 design
3
+ * system. Each rule reports findings of the same pure functions the design
4
+ * system's own checks use (`check:craft`, the replication benchmark, the vibe
5
+ * measures), so what a consumer's lint reports and what the benchmark counts
6
+ * are one thing.
7
+ *
8
+ * Usage (flat config):
9
+ * import atom63 from '@atom63/eslint-plugin'
10
+ * export default [...atom63.configs.recommended]
11
+ */
12
+ import { readFileSync } from 'node:fs'
13
+
14
+ import * as craft from './rules/craft.mjs'
15
+ import * as escapes from './rules/escapes.mjs'
16
+ import noDeprecatedValue from './rules/no-deprecated-value.mjs'
17
+ import * as warnings from './rules/warnings.mjs'
18
+
19
+ const manifest = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))
20
+
21
+ const rules = {
22
+ 'no-raw-control': escapes.noRawControl,
23
+ 'no-component-override': escapes.noComponentOverride,
24
+ 'no-reach-in-selector': escapes.noReachInSelector,
25
+ 'no-raw-value': escapes.noRawValue,
26
+ 'no-inline-style': escapes.noInlineStyle,
27
+ 'raw-color': craft.rawColor,
28
+ 'physical-properties': craft.physicalProperties,
29
+ 'focus-visible': craft.focusVisible,
30
+ 'focus-ring-outline': craft.focusRingOutline,
31
+ 'mode-branch': craft.modeBranch,
32
+ 'unknown-token': craft.unknownToken,
33
+ 'token-role': craft.tokenRole,
34
+ 'internal-token': craft.internalToken,
35
+ 'no-deprecated-value': noDeprecatedValue,
36
+ 'single-primary': warnings.singlePrimary,
37
+ 'ghost-needs-tone': warnings.ghostNeedsTone,
38
+ }
39
+
40
+ /** Rules that read class strings and tokens, in any script file. */
41
+ const sourceRules = [
42
+ 'raw-color',
43
+ 'physical-properties',
44
+ 'focus-visible',
45
+ 'focus-ring-outline',
46
+ 'mode-branch',
47
+ 'unknown-token',
48
+ 'token-role',
49
+ 'internal-token',
50
+ ]
51
+ /** Rules that read JSX. */
52
+ const jsxRules = [
53
+ 'no-raw-control',
54
+ 'no-component-override',
55
+ 'no-reach-in-selector',
56
+ 'no-raw-value',
57
+ 'no-inline-style',
58
+ 'no-deprecated-value',
59
+ ]
60
+ const warningRules = ['single-primary', 'ghost-needs-tone']
61
+
62
+ const plugin = {
63
+ meta: { name: '@atom63/eslint-plugin', version: manifest.version },
64
+ rules,
65
+ configs: {},
66
+ }
67
+
68
+ const config = (name, severity, warningSeverity) => [
69
+ {
70
+ name: `@atom63/${name}/source`,
71
+ files: ['**/*.{js,jsx,mjs,ts,tsx,mts}'],
72
+ plugins: { atom63: plugin },
73
+ rules: Object.fromEntries(sourceRules.map(rule => [`atom63/${rule}`, severity])),
74
+ },
75
+ {
76
+ name: `@atom63/${name}/jsx`,
77
+ files: ['**/*.{jsx,tsx}'],
78
+ plugins: { atom63: plugin },
79
+ rules: Object.fromEntries([
80
+ ...jsxRules.map(rule => [`atom63/${rule}`, severity]),
81
+ ...warningRules.map(rule => [`atom63/${rule}`, warningSeverity]),
82
+ ]),
83
+ },
84
+ ]
85
+
86
+ plugin.configs.recommended = config('recommended', 'error', 'warn')
87
+ plugin.configs.strict = config('strict', 'error', 'error')
88
+ plugin.configs.migrate = config('migrate', 'warn', 'warn')
89
+
90
+ export default plugin
@@ -0,0 +1,16 @@
1
+ /**
2
+ * What the rules know about the design system, generated from its sources by
3
+ * `pnpm --filter @atom63/eslint-plugin generate:data`: token names and tiers,
4
+ * the Tailwind color roles, and the deprecated values of component props.
5
+ */
6
+ import { readFileSync } from 'node:fs'
7
+
8
+ const data = JSON.parse(
9
+ readFileSync(new URL('../../generated/rule-data.json', import.meta.url), 'utf8')
10
+ )
11
+
12
+ export const knownTokens = new Set(data.knownTokens)
13
+ export const roles = data.roles
14
+ export const tiers = new Map(Object.entries(data.tiers))
15
+ export const nearestPublic = data.nearestPublic
16
+ export const deprecatedValues = data.deprecatedValues
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Every rule in this plugin reports findings of a pure function over the file
3
+ * text (the functions in `src/core`, shared with the design system's own
4
+ * checks). `defineRule` turns such a function into an ESLint rule that
5
+ * reports at the finding's line, with an optional per-file baseline.
6
+ *
7
+ * Baseline: `["error", { "baseline": { "src/legacy.tsx": 3 } }]` lets a file
8
+ * keep that many findings while it is paid down. A file over its count reports
9
+ * every finding; a file under it reports one message asking to lower the
10
+ * count, so the number only goes down. Paths are relative to ESLint's cwd.
11
+ * `atom63-lint-baseline` writes the counts from ESLint's JSON output.
12
+ */
13
+ import path from 'node:path'
14
+
15
+ const baselineSchema = {
16
+ type: 'object',
17
+ properties: {
18
+ baseline: { type: 'object', additionalProperties: { type: 'integer', minimum: 0 } },
19
+ },
20
+ additionalProperties: false,
21
+ }
22
+
23
+ /** Results of an expensive scan, once per file however many rules read it. */
24
+ export function perFile(scan) {
25
+ const cache = new WeakMap()
26
+ return sourceCode => {
27
+ if (!cache.has(sourceCode)) cache.set(sourceCode, scan(sourceCode.text, sourceCode))
28
+ return cache.get(sourceCode)
29
+ }
30
+ }
31
+
32
+ /** The whole of a 1-based line, without its indent, as an ESLint location. */
33
+ export function lineLoc(sourceCode, line) {
34
+ const text = sourceCode.lines[line - 1] ?? ''
35
+ const column = text.length - text.trimStart().length
36
+ return { start: { line, column }, end: { line, column: text.length } }
37
+ }
38
+
39
+ /**
40
+ * @param {{
41
+ * description: string,
42
+ * message: string,
43
+ * type?: 'problem' | 'suggestion',
44
+ * fixable?: 'code',
45
+ * find: (sourceCode: import('eslint').SourceCode, context: import('eslint').Rule.RuleContext) => { line: number, data?: Record<string, string>, range?: [number, number], fix?: string }[],
46
+ * }} spec
47
+ * @returns {import('eslint').Rule.RuleModule}
48
+ */
49
+ export function defineRule({ description, message, type = 'problem', fixable, find }) {
50
+ return {
51
+ meta: {
52
+ type,
53
+ docs: {
54
+ description,
55
+ url: 'https://github.com/atom63/atom63-design-system/tree/main/packages/eslint-plugin#rules',
56
+ },
57
+ ...(fixable ? { fixable } : {}),
58
+ messages: {
59
+ finding: message,
60
+ underBaseline:
61
+ '{{file}} has {{count}} of the {{allowed}} findings its baseline allows for this rule. Lower its baseline to {{count}} so it only shrinks.',
62
+ },
63
+ schema: [baselineSchema],
64
+ },
65
+ create(context) {
66
+ return {
67
+ 'Program:exit'(program) {
68
+ const { sourceCode } = context
69
+ const findings = find(sourceCode, context)
70
+ const file = path.relative(context.cwd, context.filename).split(path.sep).join('/')
71
+ const allowed = context.options[0]?.baseline?.[file] ?? 0
72
+ if (findings.length > 0 && findings.length <= allowed) {
73
+ if (findings.length < allowed) {
74
+ context.report({
75
+ node: program,
76
+ messageId: 'underBaseline',
77
+ data: { file, count: String(findings.length), allowed: String(allowed) },
78
+ })
79
+ }
80
+ return
81
+ }
82
+ if (findings.length === 0 && allowed > 0) {
83
+ context.report({
84
+ node: program,
85
+ messageId: 'underBaseline',
86
+ data: { file, count: '0', allowed: String(allowed) },
87
+ })
88
+ return
89
+ }
90
+ for (const finding of findings) {
91
+ context.report({
92
+ loc: finding.range
93
+ ? {
94
+ start: sourceCode.getLocFromIndex(finding.range[0]),
95
+ end: sourceCode.getLocFromIndex(finding.range[1]),
96
+ }
97
+ : lineLoc(sourceCode, finding.line),
98
+ messageId: 'finding',
99
+ data: finding.data ?? {},
100
+ ...(finding.fix !== undefined && finding.range
101
+ ? { fix: fixer => fixer.replaceTextRange(finding.range, finding.fix) }
102
+ : {}),
103
+ })
104
+ }
105
+ },
106
+ }
107
+ },
108
+ }
109
+ }
@@ -0,0 +1,10 @@
1
+ /** The shared scans, run once per file whichever rules read them. */
2
+ import { scanSource } from '../core/craft.mjs'
3
+ import { findSyntaxEscapes } from '../core/escapes.mjs'
4
+ import { findWarnings } from '../core/warnings.mjs'
5
+ import { knownTokens, roles, tiers } from './data.mjs'
6
+ import { perFile } from './define.mjs'
7
+
8
+ export const escapesOf = perFile(text => findSyntaxEscapes(text))
9
+ export const craftOf = perFile(text => scanSource(text, { knownTokens, roles, tiers }))
10
+ export const warningsOf = perFile(text => findWarnings(text))
@@ -0,0 +1,76 @@
1
+ /**
2
+ * The `check:craft` rules for TS/TSX (`src/core/craft.mjs`), held to the public
3
+ * token tier as a consumer's code is. Stylesheets stay with `check:craft`: no
4
+ * JS linter reads CSS.
5
+ */
6
+ import { defineRule } from '../lib/define.mjs'
7
+ import { nearestPublic } from '../lib/data.mjs'
8
+ import { craftOf } from '../lib/scans.mjs'
9
+
10
+ /** @param {string} craftRule @param {(match: string) => Record<string, string>} [data] */
11
+ const fromCraft =
12
+ (craftRule, data = match => ({ match })) =>
13
+ sourceCode =>
14
+ craftOf(sourceCode)
15
+ .filter(violation => violation.rule === craftRule)
16
+ .map(violation => ({ line: violation.line, data: data(violation.match) }))
17
+
18
+ export const rawColor = defineRule({
19
+ description: 'Take color from --a63-* tokens, not literals or the Tailwind palette.',
20
+ message:
21
+ '`{{match}}` is a literal or palette color, which ignores the theme, brand and mode. Use a `--a63-*` color role (`atom63 token <words>`).',
22
+ find: fromCraft('raw-color'),
23
+ })
24
+
25
+ export const physicalProperties = defineRule({
26
+ description: 'Use logical directions so layouts mirror in right-to-left languages.',
27
+ message:
28
+ '`{{match}}` uses a physical direction. Use its logical form (`ps-`/`pe-`, `ms-`/`me-`, `start-`/`end-`, `text-start`, `border-s`) so the layout mirrors in right-to-left languages.',
29
+ find: fromCraft('physical-properties'),
30
+ })
31
+
32
+ export const focusVisible = defineRule({
33
+ description: 'Draw focus styles on :focus-visible, not :focus.',
34
+ message: '`{{match}}` styles `:focus`, so a pointer press leaves a ring. Use `focus-visible:`.',
35
+ find: fromCraft('focus-visible'),
36
+ })
37
+
38
+ export const focusRingOutline = defineRule({
39
+ description: 'Draw focus rings as an outline, not a box-shadow ring.',
40
+ message:
41
+ '`{{match}}` draws the focus ring as a box-shadow, which a later shadow replaces and forced-colors mode drops. Use `focus-visible:outline-*`.',
42
+ find: fromCraft('focus-ring-outline'),
43
+ })
44
+
45
+ export const modeBranch = defineRule({
46
+ description: 'Do not branch on light or dark mode; tokens follow the mode.',
47
+ message:
48
+ '`{{match}}` sets a value for one mode at the call site. Use a token that follows the mode, theme and brand instead.',
49
+ find: fromCraft('mode-branch'),
50
+ })
51
+
52
+ export const unknownToken = defineRule({
53
+ description: 'Read only --a63-* tokens that exist.',
54
+ message:
55
+ '`{{match}}` is not a design-system token, so it resolves to nothing. Look the name up with `atom63 token`.',
56
+ find: fromCraft('unknown-token'),
57
+ })
58
+
59
+ export const tokenRole = defineRule({
60
+ description: 'Paint text with --a63-text-* tokens and backgrounds with fill tokens.',
61
+ message:
62
+ '`{{match}}` paints a token outside its role (a fill as text, or a text color as a background), which can fail contrast. Use `--a63-text-*` for text and fill tokens for backgrounds.',
63
+ find: fromCraft('token-role'),
64
+ })
65
+
66
+ export const internalToken = defineRule({
67
+ description: 'Read and set only public tokens.',
68
+ message: '`{{match}}` is an internal token, which can change in any release.{{hint}}',
69
+ find: fromCraft('internal-token', match => {
70
+ const nearest = nearestPublic[match.replace(/:$/, '')]
71
+ return {
72
+ match,
73
+ hint: nearest ? ` Use \`${nearest}\`.` : ' Use a public token (`atom63 token`).',
74
+ }
75
+ }),
76
+ })
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Rules over the replication benchmark's escapes (`src/core/escapes.mjs`):
3
+ * places where screen code steps outside the design system. Each reports
4
+ * exactly what the benchmark counts.
5
+ */
6
+ import { defineRule } from '../lib/define.mjs'
7
+ import { escapesOf } from '../lib/scans.mjs'
8
+
9
+ /** The component to reach for instead of each element. */
10
+ const replacements = {
11
+ a: 'Link (or a Button with render={<a />})',
12
+ button: 'Button',
13
+ details: 'Collapsible or Accordion',
14
+ dialog: 'Dialog',
15
+ input: 'Input, Checkbox, Radio or Switch',
16
+ label: 'Label or Field',
17
+ option: 'Select or Combobox items',
18
+ select: 'Select or NativeSelect',
19
+ summary: 'Collapsible or Accordion',
20
+ textarea: 'Textarea',
21
+ }
22
+
23
+ const kebab = name => name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase()
24
+
25
+ /** @param {string} escapeRule @param {(match: string) => Record<string, string>} data */
26
+ const fromEscapes = (escapeRule, data) => sourceCode =>
27
+ escapesOf(sourceCode)
28
+ .filter(escape => escape.rule === escapeRule)
29
+ .map(escape => ({ line: escape.line, data: data(escape.match) }))
30
+
31
+ export const noRawControl = defineRule({
32
+ description: 'Use a design-system component instead of an interactive HTML element.',
33
+ message:
34
+ '{{element}} rebuilds a control the design system already has. Use {{replacement}} from @atom63/ui-react (`atom63 search {{tag}}`), or pass the element as its `render` prop.',
35
+ find: fromEscapes('raw-control', match => {
36
+ const tag = match.slice(1, -1)
37
+ return { element: match, replacement: replacements[tag] ?? 'a component', tag }
38
+ }),
39
+ })
40
+
41
+ export const noComponentOverride = defineRule({
42
+ description: 'Do not repaint a design-system component through its className.',
43
+ message:
44
+ '`{{utility}}` repaints <{{component}}>. Its className may only place it (margin, size, position, layout). Use its props instead (`atom63 component {{slug}}`), or note the missing prop with a `gap:` comment.',
45
+ find: fromEscapes('component-override', match => {
46
+ const [component, utility] = match.split(' ')
47
+ return { component, utility, slug: kebab(component.split('.')[0]) }
48
+ }),
49
+ })
50
+
51
+ export const noReachInSelector = defineRule({
52
+ description: 'Do not style markup you do not own through an arbitrary variant.',
53
+ message:
54
+ '`{{token}}` styles markup inside another element from outside. Use a prop or variant of the component; if the system lacks one, note it with a `gap:` comment.',
55
+ find: fromEscapes('arbitrary-selector', token => ({ token })),
56
+ })
57
+
58
+ export const noRawValue = defineRule({
59
+ description: 'Take lengths and values from the spacing scale and tokens, not arbitrary values.',
60
+ message:
61
+ '`{{token}}` hardcodes a value. Use a spacing step or size utility, or read a `--a63-*` token (`atom63 token <words>`).',
62
+ find: fromEscapes('arbitrary-value', token => ({ token })),
63
+ })
64
+
65
+ export const noInlineStyle = defineRule({
66
+ description: 'Style with classes and tokens, not the style prop.',
67
+ message:
68
+ '`style` sets values outside the system. Use classes and `--a63-*` tokens; for a value computed at runtime, disable this line with a reason.',
69
+ find: fromEscapes('inline-style', () => ({})),
70
+ })
@@ -0,0 +1,71 @@
1
+ /**
2
+ * `no-deprecated-value`: a prop value a component contract lists as a
3
+ * deprecated alias, such as `size="default"` on Dialog, which became `md`.
4
+ * The values come from the contracts' `deprecatedAliases`; the fix writes the
5
+ * value that replaced it.
6
+ */
7
+ import ts from 'typescript'
8
+
9
+ import { deprecatedValues } from '../lib/data.mjs'
10
+ import { defineRule, perFile } from '../lib/define.mjs'
11
+
12
+ /* Longest first, so AlertDialog wins over a shorter name it starts with. */
13
+ const components = Object.keys(deprecatedValues).sort((a, b) => b.length - a.length)
14
+
15
+ const findDeprecated = perFile(text => {
16
+ const file = ts.createSourceFile(
17
+ 'file.tsx',
18
+ text,
19
+ ts.ScriptTarget.Latest,
20
+ true,
21
+ ts.ScriptKind.TSX
22
+ )
23
+ const systemNames = new Map()
24
+ for (const statement of file.statements) {
25
+ if (!ts.isImportDeclaration(statement)) continue
26
+ const from = /** @type {import('typescript').StringLiteral} */ (statement.moduleSpecifier).text
27
+ const bindings = statement.importClause?.namedBindings
28
+ if (!from.startsWith('@atom63/') || !bindings || !ts.isNamedImports(bindings)) continue
29
+ for (const element of bindings.elements)
30
+ systemNames.set(element.name.text, (element.propertyName ?? element.name).text)
31
+ }
32
+ const findings = []
33
+ const visit = node => {
34
+ if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
35
+ const [local, ...member] = node.tagName.getText(file).split('.')
36
+ const imported = systemNames.get(local)
37
+ const name = imported && [imported, ...member].join('')
38
+ const component = name && components.find(candidate => name.startsWith(candidate))
39
+ if (component) {
40
+ for (const attribute of node.attributes.properties) {
41
+ if (!ts.isJsxAttribute(attribute) || !attribute.initializer) continue
42
+ const prop = attribute.name.getText(file)
43
+ let literal = attribute.initializer
44
+ if (ts.isJsxExpression(literal) && literal.expression) literal = literal.expression
45
+ if (!ts.isStringLiteral(literal)) continue
46
+ const replacement = deprecatedValues[component][prop]?.[literal.text]
47
+ if (!replacement) continue
48
+ const start = literal.getStart(file)
49
+ const quote = text[start]
50
+ findings.push({
51
+ line: file.getLineAndCharacterOfPosition(start).line + 1,
52
+ range: [start, literal.getEnd()],
53
+ fix: `${quote}${replacement}${quote}`,
54
+ data: { prop, value: literal.text, replacement, component: name },
55
+ })
56
+ }
57
+ }
58
+ }
59
+ ts.forEachChild(node, visit)
60
+ }
61
+ visit(file)
62
+ return findings
63
+ })
64
+
65
+ export default defineRule({
66
+ description: 'Use the current name of a component prop value, not a deprecated alias.',
67
+ message:
68
+ '{{prop}}="{{value}}" on <{{component}}> is a deprecated name; use {{prop}}="{{replacement}}". The alias goes away in a breaking release.',
69
+ fixable: 'code',
70
+ find: sourceCode => findDeprecated(sourceCode),
71
+ })
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Rules over the vibe measures' Button warnings (`src/core/warnings.mjs`):
3
+ * patterns that are not wrong but usually unintended. Warnings by default.
4
+ */
5
+ import { defineRule } from '../lib/define.mjs'
6
+ import { warningsOf } from '../lib/scans.mjs'
7
+
8
+ /** @param {string} warning */
9
+ const fromWarnings = warning => sourceCode =>
10
+ warningsOf(sourceCode)
11
+ .filter(found => found.rule === warning)
12
+ .map(found => ({ line: found.line }))
13
+
14
+ export const singlePrimary = defineRule({
15
+ type: 'suggestion',
16
+ description: 'Give a view at most one primary Button.',
17
+ message:
18
+ 'This is the second `variant="primary"` Button in the file. Keep one primary action per view; make the others `default`, `outline` or `ghost`.',
19
+ find: fromWarnings('multiple-primary'),
20
+ })
21
+
22
+ export const ghostNeedsTone = defineRule({
23
+ type: 'suggestion',
24
+ description: 'Draw secondary ghost Buttons with tone="muted".',
25
+ message:
26
+ 'A `variant="ghost"` Button with no `tone`. Secondary actions in toolbars, rows and card headers take `tone="muted"`, which rests in the secondary text color.',
27
+ find: fromWarnings('ghost-without-tone'),
28
+ })