@seanyeh77/eslint-plugin-ui 0.52.1 → 0.53.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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @seanyeh77/eslint-plugin-ui
2
2
 
3
- 讓用 `@seanyeh77/ui` 寫的程式碼守住設計系統規則的 ESLint 規則:只用 token 顏色(`no-raw-color`、`no-tailwind-defaults`)、用元件取代原生控制項(`no-native-controls`)、卡片裡不再放卡片(`no-nested-card`)、每區最多一個主要按鈕(`one-primary-button`)、按鈕文字用動詞(`verb-labels`)、危險動作要確認(`danger-confirm`)、間距、字級、字體、圓角和陰影用 token(`no-raw-size`)。
3
+ 讓用 `@seanyeh77/ui` 寫的程式碼守住設計系統規則的 ESLint 規則:只用 token 顏色(`no-raw-color`、`no-tailwind-defaults`)、用元件取代原生控制項(`no-native-controls`)、卡片裡不再放卡片(`no-nested-card`)、區塊之間的距離由 Page 和 Grid 決定(`no-custom-block-gap`)、每區最多一個主要按鈕(`one-primary-button`)、按鈕文字用動詞(`verb-labels`)、危險動作要確認(`danger-confirm`)、間距、字級、字體、圓角和陰影用 token(`no-raw-size`)。
4
4
 
5
5
  ## 安裝
6
6
 
@@ -25,6 +25,7 @@ export default [ui.configs.recommended];
25
25
  | `no-tailwind-defaults` | error | Tailwind 自己的色盤、圓角和陰影(`bg-gray-100`、`rounded-xl`、`shadow-lg`) |
26
26
  | `no-native-controls` | error | 系統有元件取代的原生元素:`<select>`、`<table>`、`<dialog>`、`<progress>`、`<textarea>`、`<button>`(用 Button 或 IconButton)、`<a>`(用 Link),以及沒有 type 或 type 為 text、search、email、password、number、range、checkbox、radio、date、file、color、submit 的 `<input>`。帶 `ui-` 開頭 class 的原生元素(`<button className="ui-link-btn">`)和有 `hidden` 屬性的 `<input>`(看不到,例如由按鈕打開的檔案選擇)不算;檔案選擇改用 FileUpload 或 `useFilePicker` |
27
27
  | `no-nested-card` | error | Card 裡再放 Card |
28
+ | `no-custom-block-gap` | error | Page 或 Grid 裡自己設 `gap`、`margin` 的包裝 `div`(或 Card、Alert 自己的 margin),讓區塊之間的距離和頁面其他地方不同;改用 Page(Grid 的一欄放一個 Page),區塊之間一律是 `block-gap` |
28
29
  | `danger-confirm` | error | 沒有 `confirm` 的危險按鈕,`variant={x ? 'danger' : 'quiet'}` 也算 |
29
30
  | `one-primary-button` | warn | 同一區第二個主要按鈕,條件式的 `variant` 也算 |
30
31
  | `verb-labels` | warn | 「確定」「OK」「是」這類只回答對話框、不說明動作的按鈕文字;「送出」「儲存」這類動詞可以 |
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ declare const rules: {
8
8
  'verb-labels': Rule.RuleModule;
9
9
  'danger-confirm': Rule.RuleModule;
10
10
  'no-raw-size': Rule.RuleModule;
11
+ 'no-custom-block-gap': Rule.RuleModule;
11
12
  };
12
13
  declare const plugin: ESLint.Plugin & {
13
14
  configs: Record<string, Linter.Config>;
package/dist/index.js CHANGED
@@ -548,4 +548,4 @@ ${n?`...and ${n} more files\n`:``}
548
548
  If you absolutely need more files included, set parserOptions.projectService.maximumDefaultProjectFileMatchCount_THIS_WILL_SLOW_DOWN_LINTING to a larger value.
549
549
  `)}return{filePathAbsolute:n,opened:a};function o(e=n){return i.service.openClientFile(e,r.codeFullText,void 0,r.tsconfigRootDir)}function s(){if(t)return;let e=S(i.service,n);if(e==null)return;_(`Retrying with the path a project knows the file by: %s`,e);let r=o(e);return r.configFileName?{filePathAbsolute:e,opened:r}:void 0}function c(){_(`Opening project service client file at path: %s`,n);let e=o();return!e.configFileErrors&&!e.configFileName&&!r.singleRun&&!t&&performance.now()-i.lastReloadTimestamp>250&&(_(`No config file found; reloading project service and retrying.`),i.service.reloadProjects(),e=o(),i.lastReloadTimestamp=performance.now()),e}}function S(e,t){for(let n of e.configuredProjects.values()){let e=(0,h.createSymlinkedDirectories)(n.getFileNames(!0,!0)),r=(0,h.getPathToSameFile)(e,t);if(r!=null)return r}}function C(e,t,n){return _(`No project service information available. Creating no program.`),n.getScriptInfo(e)&&(_(`Script info available. Opening client file in project service.`),n.openClientFile(e,t.codeFullText,void 0,t.tsconfigRootDir)),(0,m.createNoProgram)(t)}function w(e,t,n){_(`Retrieving script info and then program for: %s`,e);let r=n.service.getScriptInfo(e),i=n.service.getDefaultProjectForFile(r.fileName,!0).getLanguageService(!0).getProgram();if(!i)_(`Could not find project service program for: %s`,e);else return _(`Found project service program for: %s`,e),(0,f.createProjectProgram)(t,[i])}function T(e,t,n,r){y(e.service,t.extraFileExtensions);let i=E(t.filePath,e);_(`Opening project service file for: %s at absolute path %s`,t.filePath,i);let a=D(l.default.relative(t.tsconfigRootDir,i),e.allowDefaultProject);if(!n&&!a)return C(i,t,e.service);let o=n&&x(r,a,i,t,e);return _(`Opened project service file: %o`,o),w(o?o.filePathAbsolute:i,t,e)}function E(e,t){return l.default.isAbsolute(e)?e:l.default.join(t.service.host.getCurrentDirectory(),e)}function D(e,t){return!!t?.some(t=>(0,c.minimatch)(e,t,{dot:!0}))}})),ca=/* @__PURE__ */ u(((e,t,n)=>{var r=n&&n.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||(`get`in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),i=n&&n.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),a=n&&n.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},e(t)};return function(t){if(t&&t.__esModule)return t;var n={};if(t!=null)for(var a=e(t),o=0;o<a.length;o++)a[o]!=="default"&&r(n,t,a[o]);return i(n,t),n}})(),o=n&&n.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.clearProgramCache=D,e.clearDefaultProjectMatchedFiles=A,e.parse=j,e.clearParseAndGenerateServicesCalls=M,e.parseAndGenerateServices=re;let s=o(or()),c=a(b()),l=bi(),u=gi(),d=Si(),f=Ti(),p=Ei(),m=fr(),h=dr(),g=Di(),_=Oi(),v=Zi(),y=Li(),x=Qi(),S=sa(),C=(0,s.default)(`typescript-eslint:typescript-estree:parser`),w=/* @__PURE__ */ new Map,T=/* @__PURE__ */ new Set,E=/* @__PURE__ */ new Map;function D(){w.clear(),T.clear(),E.clear()}function O(e){if(e.extraFileExtensions.length||e.projectService?.allowDefaultProject?.length)return;let t;try{[t]=(0,y.getProjectConfigFiles)({...e,tsconfigMatchCache:E},!0,[`tsconfig.json`,`jsconfig.json`])??[]}catch{return}if(!t)return;let n=(0,h.getCanonicalFileName)(t);if(T.has(n))return;let r=w.get(n);if(!r){if(c.readConfigFile(t,c.sys.readFile).config?.references?.length){T.add(n);return}C(`Creating single-run Program for project service: %s`,t),r=(0,g.createProgramFromConfigFile)(t,void 0,e.jsDocParsingMode),w.set(n,r)}let i=(0,h.getAstFromProgram)(r,e.filePath);if(i?.ast.text===e.codeFullText)return i.program.getTypeChecker(),i}let k=/* @__PURE__ */ new Set;function A(){k.clear()}function ee(e,t){if(e.projectService){if(e.singleRun&&t){let t=O(e);if(t)return t}let n=(0,S.useProgramFromProjectService)(e.projectService,e,t,k);if(n)return n}return e.programs?(0,g.useProvidedPrograms)(e.programs,e):t?(0,f.createProjectProgram)(e,(0,m.getWatchProgramsForProjects)(e)):(0,p.createNoProgram)(e)}function j(e,t){let{ast:n}=te(e,t,!1);return n}function te(e,t,n){let r=(0,v.createParseSettings)(e,t);if(t?.errorOnTypeScriptSyntacticAndSemanticIssues)throw Error(`"errorOnTypeScriptSyntacticAndSemanticIssues" is only supported for parseAndGenerateServices()`);let i=(0,p.createSourceFile)(r),{astMaps:a,estree:o}=(0,l.astConverter)(i,r,n);return{ast:o,esTreeNodeToTSNodeMap:a.esTreeNodeToTSNodeMap,tsNodeToESTreeNodeMap:a.tsNodeToESTreeNodeMap}}let ne={};function M(){ne={}}function re(e,t){let n=(0,v.createParseSettings)(e,t);n.singleRun&&!n.programs&&n.projects.size>0&&(n.programs={*[Symbol.iterator](){for(let e of n.projects){let t=w.get(e[0]);if(t)yield t;else{C(`Detected single-run/CLI usage, creating Program once ahead of time for project: %s`,e);let t=(0,g.createProgramFromConfigFile)(e[1]);w.set(e[0],t),yield t}}}});let r=n.programs!=null||n.projects.size>0||!!n.projectService;if(typeof t.errorOnTypeScriptSyntacticAndSemanticIssues==`boolean`&&t.errorOnTypeScriptSyntacticAndSemanticIssues&&(n.errorOnTypeScriptSyntacticAndSemanticIssues=!0),n.errorOnTypeScriptSyntacticAndSemanticIssues&&!r)throw Error(`Cannot calculate TypeScript semantic issues without a valid project.`);n.singleRun&&t.filePath&&(ne[t.filePath]=(ne[t.filePath]||0)+1);let{ast:i,program:a}=n.singleRun&&t.filePath&&ne[t.filePath]>1&&!n.projectService?(0,d.createIsolatedProgram)(n):ee(n,r),o=typeof n.preserveNodeMaps!=`boolean`||n.preserveNodeMaps,{astMaps:s,estree:c}=(0,l.astConverter)(i,n,o);if(a&&n.errorOnTypeScriptSyntacticAndSemanticIssues){let e=(0,x.getFirstSemanticOrSyntacticError)(a,i);if(e)throw(0,u.convertError)(e)}return{ast:c,services:(0,_.createParserServices)(s,a)}}})),la=/* @__PURE__ */ u((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.clearProgramCache=void 0,e.clearCaches=s;let t=fr(),n=dr(),r=ca(),i=Fi(),a=Zi(),o=qi();function s(){(0,i.clearCandidateTSConfigRootDirs)(),(0,r.clearDefaultProjectMatchedFiles)(),(0,r.clearProgramCache)(),(0,n.clearRealPathCache)(),(0,t.clearWatchCaches)(),(0,a.clearTSConfigMatchCache)(),(0,a.clearTSServerProjectService)(),(0,o.clearGlobCache)()}e.clearProgramCache=s})),ua=/* @__PURE__ */ u((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.withoutProjectParserOptions=t;function t(e){let{EXPERIMENTAL_useProjectService:t,project:n,projectService:r,...i}=e;return i}})),da=/* @__PURE__ */ u(((e,t,n)=>{var r=n&&n.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||(`get`in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),i=n&&n.__exportStar||function(e,t){for(var n in e)n!=="default"&&!Object.prototype.hasOwnProperty.call(t,n)&&r(t,e,n)};Object.defineProperty(e,"__esModule",{value:!0}),e.withoutProjectParserOptions=e.version=e.typescriptVersionIsAtLeast=e.simpleTraverse=e.clearCandidateTSConfigRootDirs=e.addCandidateTSConfigRootDir=e.parseAndGenerateServices=e.parse=e.TSError=e.createProgram=e.getCanonicalFileName=void 0,i(la(),e),i(xi(),e);var a=dr();Object.defineProperty(e,"getCanonicalFileName",{enumerable:!0,get:function(){return a.getCanonicalFileName}});var o=Di();Object.defineProperty(e,"createProgram",{enumerable:!0,get:function(){return o.createProgramFromConfigFile}}),i(si(),e);var s=fi();Object.defineProperty(e,"TSError",{enumerable:!0,get:function(){return s.TSError}});var c=ca();Object.defineProperty(e,"parse",{enumerable:!0,get:function(){return c.parse}}),Object.defineProperty(e,"parseAndGenerateServices",{enumerable:!0,get:function(){return c.parseAndGenerateServices}});var l=Fi();Object.defineProperty(e,"addCandidateTSConfigRootDir",{enumerable:!0,get:function(){return l.addCandidateTSConfigRootDir}}),Object.defineProperty(e,"clearCandidateTSConfigRootDirs",{enumerable:!0,get:function(){return l.clearCandidateTSConfigRootDirs}});var u=yi();Object.defineProperty(e,"simpleTraverse",{enumerable:!0,get:function(){return u.simpleTraverse}}),i(di(),e);var d=oi();Object.defineProperty(e,"typescriptVersionIsAtLeast",{enumerable:!0,get:function(){return d.typescriptVersionIsAtLeast}});var f=Yi();Object.defineProperty(e,"version",{enumerable:!0,get:function(){return f.version}});var p=ua();Object.defineProperty(e,"withoutProjectParserOptions",{enumerable:!0,get:function(){return p.withoutProjectParserOptions}})})),fa=/* @__PURE__ */ u(((e,t,n)=>{var r=n&&n.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.parse=p,e.parseForESLint=m;let i=tr(),a=da(),o=w(),s=r(or()),c=b(),l=(0,s.default)(`typescript-eslint:parser:parser`);function u(e,t=!1){return typeof e==`boolean`?e:t}let d=/lib\.(.+)\.d\.[cm]?ts$/;function f(e){if(e.lib)return e.lib.map(e=>d.exec(e.toLowerCase())?.[1]).filter(e=>!!e);let t=a.typescriptVersionIsAtLeast[`6.0`]?c.ScriptTarget.LatestStandard:c.ScriptTarget.ES5;switch(e.target??t){case c.ScriptTarget.ES2015:return[`es6`];case c.ScriptTarget.ES2016:return[`es2016.full`];case c.ScriptTarget.ES2017:return[`es2017.full`];case c.ScriptTarget.ES2018:return[`es2018.full`];case c.ScriptTarget.ES2019:return[`es2019.full`];case c.ScriptTarget.ES2020:return[`es2020.full`];case c.ScriptTarget.ES2021:return[`es2021.full`];case c.ScriptTarget.ES2022:return[`es2022.full`];case c.ScriptTarget.ES2023:return[`es2023.full`];case c.ScriptTarget.ES2024:return[`es2024.full`];case c.ScriptTarget.ES2025:return[`es2025.full`];case c.ScriptTarget.ESNext:return[`esnext.full`];default:return[`lib`]}}function p(e,t){return m(e,t).ast}function m(e,t){if(t=!t||typeof t!=`object`?{}:{...t},t.sourceType!==`module`&&t.sourceType!==`script`&&(t.sourceType=`script`),typeof t.ecmaFeatures!=`object`&&(t.ecmaFeatures={}),t.onUnsupportedTypeScriptVersion!=null&&t.warnOnUnsupportedTypeScriptVersion!=null)throw Error("Cannot use both the `onUnsupportedTypeScriptVersion` and the deprecated `warnOnUnsupportedTypeScriptVersion` options. Please use only `onUnsupportedTypeScriptVersion`.");let n=t.onUnsupportedTypeScriptVersion??(u(t.warnOnUnsupportedTypeScriptVersion,!0)?`warn`:`ignore`),r={jsx:u(t.ecmaFeatures.jsx),...t,onUnsupportedTypeScriptVersion:n,errorOnTypeScriptSyntacticAndSemanticIssues:!1,comment:!0,loc:!0,range:!0,tokens:!0},s={globalReturn:t.ecmaFeatures.globalReturn,jsxFragmentName:t.jsxFragmentName,jsxPragma:t.jsxPragma,lib:t.lib,sourceType:t.sourceType},{ast:c,services:d}=(0,a.parseAndGenerateServices)(e,r);if(c.sourceType=t.sourceType,d.program){let e=d.program.getCompilerOptions();s.lib??(s.lib=f(e),l(`Resolved libs from program: %o`,s.lib)),s.jsxPragma===void 0&&e.jsxFactory!=null&&(s.jsxPragma=e.jsxFactory.split(`.`)[0].trim(),l(`Resolved jsxPragma from program: %s`,s.jsxPragma)),s.jsxFragmentName===void 0&&e.jsxFragmentFactory!=null&&(s.jsxFragmentName=e.jsxFragmentFactory.split(`.`)[0].trim(),l(`Resolved jsxFragmentName from program: %s`,s.jsxFragmentName))}let p=(0,i.analyze)(c,s);return d.emitDecoratorMetadata??=t.emitDecoratorMetadata===!0,d.experimentalDecorators??=t.experimentalDecorators===!0,d.isolatedDeclarations??=t.isolatedDeclarations===!0,{ast:c,scopeManager:p,services:d,visitorKeys:o.visitorKeys}}})),pa=/* @__PURE__ */ u(((e,t)=>{t.exports={name:`@typescript-eslint/parser`,version:`8.72.1`,description:`An ESLint custom parser which leverages TypeScript ESTree`,files:[`dist`,`!**/*.js.map`,`!**/*.tsbuildinfo`],type:`commonjs`,exports:{".":{types:`./dist/index.d.ts`,default:`./dist/index.js`},"./package.json":`./package.json`},engines:{node:`^18.18.0 || ^20.9.0 || >=21.1.0`},repository:{type:`git`,url:`https://github.com/typescript-eslint/typescript-eslint.git`,directory:`packages/parser`},bugs:{url:`https://github.com/typescript-eslint/typescript-eslint/issues`},homepage:`https://typescript-eslint.io/packages/parser`,license:`MIT`,keywords:[`ast`,`ecmascript`,`javascript`,`typescript`,`parser`,`syntax`,`eslint`],peerDependencies:{eslint:`^8.57.0 || ^9.0.0 || ^10.0.0`,typescript:`>=4.8.4 <6.1.0`},dependencies:{"@typescript-eslint/scope-manager":`8.72.1`,"@typescript-eslint/types":`8.72.1`,"@typescript-eslint/typescript-estree":`8.72.1`,"@typescript-eslint/visitor-keys":`8.72.1`,debug:`^4.4.3`},devDependencies:{"@typescript/native":`npm:typescript@^7.0.2`,"@vitest/coverage-v8":`^5.0.3`,eslint:`^10.0.0`,glob:`^11.1.0`,rimraf:`^5.0.10`,typescript:`>=4.8.4 <6.1.0`,vitest:`^5.0.3`},funding:{type:`opencollective`,url:`https://opencollective.com/typescript-eslint`},nx:{name:`parser`,includedScripts:[`clean`],targets:{lint:{command:`eslint`},"typecheck:tsc6":{},"attw-check":{}}},scripts:{build:`pnpm exec nx build`,clean:`rimraf dist/ coverage/`,format:`pnpm -w run format`,lint:`pnpm -w exec nx lint`,test:`pnpm -w exec nx test`,typecheck:`pnpm -w exec nx typecheck`,"typecheck:tsc6":`pnpm -w exec nx typecheck:tsc6`,"attw-check":`pnpm -w exec nx attw-check`}}})),ma=/* @__PURE__ */ u(((e,t,n)=>{var r=n&&n.__createBinding||(Object.create?(function(e,t,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||(`get`in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]})),i=n&&n.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),a=n&&n.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},e(t)};return function(t){if(t&&t.__esModule)return t;var n={};if(t!=null)for(var a=e(t),o=0;o<a.length;o++)a[o]!=="default"&&r(n,t,a[o]);return i(n,t),n}})();Object.defineProperty(e,"__esModule",{value:!0}),e.meta=e.version=e.withoutProjectParserOptions=e.createProgram=e.clearCaches=e.parseForESLint=e.parse=void 0;let[o,s]=a(b()).versionMajorMinor.split(`.`).map(Number);if(o>=7)throw console.error(`typescript-eslint does not support TS 7.0.
550
550
  Please see https://devblogs.microsoft.com/typescript/announcing-typescript-7-0/#running-side-by-side-with-typescript-6.0 to run typescript-eslint using the TS 6 API.
551
- See also https://github.com/typescript-eslint/typescript-eslint/issues/10940 for tracking typescript-eslint's support for TS >=7.1`),Error(`typescript-eslint does not support TS 7.0.`);var c=fa();Object.defineProperty(e,"parse",{enumerable:!0,get:function(){return c.parse}}),Object.defineProperty(e,"parseForESLint",{enumerable:!0,get:function(){return c.parseForESLint}});var l=da();Object.defineProperty(e,"clearCaches",{enumerable:!0,get:function(){return l.clearCaches}}),Object.defineProperty(e,"createProgram",{enumerable:!0,get:function(){return l.createProgram}}),Object.defineProperty(e,"withoutProjectParserOptions",{enumerable:!0,get:function(){return l.withoutProjectParserOptions}}),e.version=pa().version,e.meta={name:`typescript-eslint/parser`,version:e.version}})),ha=`@seanyeh77/eslint-plugin-ui`,ga=`0.52.1`,_a=/* @__PURE__ */ f(ma(),1);const va=e=>e.value,ya=/#[0-9a-fA-F]{3,8}\b|\brgba?\(|\bhsla?\(|\boklch\(/,ba=/url\(\s*['"]?#[^)]*\)/g,xa=/^(black|white|red|green|blue|yellow|orange|purple|pink|gray|grey|brown|cyan|magenta|navy|teal|maroon|olive|lime|aqua|fuchsia|silver|gold|indigo|violet|crimson|tomato|coral|salmon|khaki|beige|ivory|lavender|tan|darkgray|darkgrey|lightgray|lightgrey|darkblue|lightblue|darkred|darkgreen|lightgreen)$/i,Sa=/color|background|fill|stroke|border|outline|shadow/i,Ca=/-\[(#|rgba?\(|hsla?\(|oklch\()/;function wa(e){let t=e.name;return t.type===`JSXIdentifier`?t.name??``:t.type===`JSXMemberExpression`?t.property?.name??``:``}function Ta(e,t){return e.attributes.find(e=>e.type===`JSXAttribute`&&e.name?.name===t)}function Ea(e){return e?e.type===`Literal`?[e.value]:e.type===`ConditionalExpression`?[...Ea(e.consequent),...Ea(e.alternate)]:e.type===`LogicalExpression`?e.operator===`&&`?Ea(e.right):[...Ea(e.left),...Ea(e.right)]:e.type===`TSAsExpression`||e.type===`TSSatisfiesExpression`||e.type===`TSNonNullExpression`?Ea(e.expression):[]:[]}function Da(e){return e?e.value?e.value.type===`Literal`?[e.value.value]:e.value.type===`JSXExpressionContainer`?Ea(e.value.expression):[]:[!0]:[]}const Oa=(e,t)=>Da(e).includes(t);function ka(e){return e.children.map(e=>{let t=e;return t.type===`JSXText`?t.value??``:t.type===`JSXExpressionContainer`&&t.expression?.type===`Literal`?String(t.expression.value):`\0`}).join(``).trim()}const Aa=/* @__PURE__ */ RegExp(`^(bg|text|border(?:-[trblxyse])?|ring(?:-offset)?|inset-ring|outline|divide(?:-[xy])?|fill|stroke|from|via|to|placeholder|decoration|caret|accent|shadow|inset-shadow|drop-shadow|text-shadow)-(?:(?:slate|gray|zinc|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(?:50|[1-9]00|950)|white|black)(?:/(?:[\\d.]+|\\[[^\\]]+\\]|\\([^)]+\\)))?$`),ja=/^rounded(?:-[trblse]{1,2})?(?:-(?:xs|xl|2xl|3xl|4xl))?$/,Ma=/^(?:shadow|drop-shadow|inset-shadow)(?:-(?:2xs|xs|md|lg|xl|2xl|inner))?$/,Na=`cn|clsx|cx|cva|twMerge|twJoin|tv|classnames`,Pa=e=>{for(let t=e.parent;t;t=t.parent){let e=t;if(e.type===`JSXAttribute`)return e.name?.name===`className`||e.name?.name===`class`}return!1},Fa=RegExp(`^(${Na})$`),Ia=e=>{let t;for(let n=e,r=e.parent;r;n=r,r=r.parent){let e=r;if(e.type===`JSXAttribute`)return e.name?.name===`className`||e.name?.name===`class`;if(e.type===`CallExpression`)return Fa.test(e.callee?.name??``);if(e.type===`BinaryExpression`||e.type===`SwitchCase`||e.type===`MemberExpression`&&e.computed&&e.property===n)return!1;if(e.type===`Property`&&e.key===n)return La(r);if(e.type===`Property`){let n=Ra(e.key);if(t??=n,n===`defaultVariants`||(n===`compoundVariants`||n===`compoundSlots`)&&t!==`class`&&t!==`className`)return!1}}return!1},La=e=>{let t=e.parent;if(t?.type!==`ObjectExpression`)return!1;let n=t.parent;for(;n?.type===`ArrayExpression`;)n=n.parent;return n?.type===`CallExpression`&&Fa.test(n.callee?.name??``)},Ra=e=>{let t=e;return t?.type===`Identifier`?t.name:typeof t?.value==`string`?t.value:void 0},za={text:`text-ink, text-ink-muted, text-accent-text, text-danger-text, text-on-accent`,bg:`bg-surface, bg-surface-sub, bg-accent, bg-accent-soft, bg-danger-soft`,border:`border-line, border-line-strong, border-accent`},Ba=e=>e.split(/\s+/).filter(Boolean).map(e=>e.slice(e.lastIndexOf(`:`)+1).replace(/^!|!$/g,``));function Va(e){let t=e=>e.value.cooked??``;return{"JSXAttribute[name.name=/^(className|class)$/] Literal"(t){let n=va(t);typeof n==`string`&&Ia(t)&&e(t,n)},"JSXAttribute[name.name=/^(className|class)$/] TemplateElement"(n){Ia(n)&&e(n,t(n))},[`CallExpression[callee.name=/^(${Na})$/] TemplateElement`](n){!Pa(n)&&Ia(n)&&e(n,t(n))},[`CallExpression[callee.name=/^(${Na})$/] Literal`](t){if(Pa(t))return;let n=va(t);typeof n==`string`&&Ia(t)&&e(t,n)}}}const Ha={meta:{type:`suggestion`,docs:{description:`Disallow Tailwind's default palette, radii and shadows: use the design system's token classes.`},schema:[]},create(e){return Va((t,n)=>{for(let r of Ba(n)){let n=Aa.exec(r);if(n){let i=n[1].startsWith(`border`)?`border`:n[1];e.report({node:t,message:`{{c}} is Tailwind's palette, not a design-system color. Use a token class: {{hint}}.`,data:{c:r,hint:za[i]??`${n[1]}-ink, ${n[1]}-accent, ${n[1]}-line`}})}else ja.test(r)?e.report({node:t,message:`{{c}} is not a design-system radius. Use rounded-sm, rounded-md or rounded-lg.`,data:{c:r}}):Ma.test(r)&&e.report({node:t,message:`{{c}} is not a design-system shadow. Use shadow-card, shadow-overlay or shadow-sm.`,data:{c:r}})}})}},Ua={meta:{type:`problem`,docs:{description:`Colors come from tokens: var(--ink) or cssVar("ink"), never a hex, rgb() or hsl() value.`},schema:[]},create(e){let t=(t,n,r=``)=>{(ya.test(n.replace(ba,``))||Sa.test(r)&&xa.test(n.trim()))&&e.report({node:t,message:`Hard-coded color "{{v}}". Use a token: var(--ink-muted) in CSS, cssVar("ink-muted") from @seanyeh77/tokens in style props, or a component prop.`,data:{v:n.slice(0,40)}})};return{'JSXAttribute[name.name="style"] Literal'(e){let n=va(e);if(typeof n!=`string`)return;let r=e.parent,i=!0;for(let t=e;r&&r.type!==`Property`;t=r,r=r.parent){let e=r;if(e.type===`MemberExpression`&&e.computed&&e.property===t)return;e.type===`ConditionalExpression`&&e.test!==t||[`LogicalExpression`,`TSAsExpression`,`TSSatisfiesExpression`,`TSNonNullExpression`].includes(e.type)||(i=!1)}if(!r)return;let a=r.key;a!==e&&t(e,n,i?String(a?.name??a?.value??``):``)},"JSXAttribute[name.name=/^(className|class)$/] Literal"(t){let n=va(t);typeof n==`string`&&Ca.test(n)&&e.report({node:t,message:`Arbitrary color in "{{v}}". Use the token classes of @seanyeh77/tokens/tailwind.css: bg-surface, text-ink-muted.`,data:{v:n.slice(0,40)}})},'JSXAttribute[name.name="style"] Property > TemplateLiteral > TemplateElement'(e){t(e,String(va(e).raw))},"JSXAttribute[name.name=/^(fill|stroke|color|stopColor|floodColor)$/] Literal"(e){let n=va(e);typeof n==`string`&&t(e,n,`color`)}}}},Wa={select:`Select (or MultiSelect)`,table:`DataTable`,dialog:`Dialog`,progress:`ProgressBar`,textarea:`TextArea`,button:`Button (or IconButton for an icon alone)`,a:`Link`},Ga={"":`TextField`,text:`TextField`,email:`TextField type="email"`,password:`TextField type="password"`,number:`TextField type="number"`,tel:`TextField type="tel"`,url:`TextField type="url"`,range:`TextField type="number" or SegmentedControl`,checkbox:`Checkbox (or Switch for an on/off setting)`,radio:`RadioGroup`,date:`DatePicker`,search:`SearchField`,file:`FileUpload for a drop area, or useFilePicker to open the picker from a button or menu item`,color:`AccentPicker`,submit:`Button`,button:`Button`,reset:`Button`},Ka={meta:{type:`problem`,docs:{description:`Use the design-system component instead of a native control it replaces.`},schema:[{type:`object`,properties:{allow:{type:`array`,items:{type:`string`},description:`Native tags to allow, e.g. ["a"] when links come from a router.`}},additionalProperties:!1}]},create(e){let t=new Set((e.options[0]?.allow??[]).map(e=>e.toLowerCase()));return{JSXOpeningElement(n){let r=n;if(r.name.type!==`JSXIdentifier`)return;let i=wa(r);if(!t.has(i)&&!Da(Ta(r,`className`)).some(e=>typeof e==`string`&&/(^|\s)ui-[a-z]/.test(e))&&(Wa[i]&&e.report({node:n,message:`Native <{{n}}>: use {{c}} from @seanyeh77/ui.`,data:{n:i,c:Wa[i]}}),i===`input`)){let i=Ta(r,`hidden`);if(i&&Da(i).length&&Da(i).every(e=>e===!0||e===``||e===`hidden`))return;let a=Ta(r,`type`),o=a?Da(a):[``];for(let r of new Set(o))typeof r==`string`&&Ga[r.toLowerCase()]&&!t.has(`input[type=${r||`text`}]`)&&e.report({node:n,message:`<input{{t}}>: use {{c}} from @seanyeh77/ui.`,data:{t:r?` type="${r}"`:``,c:Ga[r.toLowerCase()]}})}}}}},qa={meta:{type:`problem`,docs:{description:`No Card inside a Card: one shadow per block.`},schema:[]},create(e){return{JSXElement(t){let n=t;if(wa(n.openingElement)===`Card`){for(let r=n.parent;r;r=r.parent)if(r.type===`JSXElement`&&wa(r.openingElement)===`Card`){e.report({node:t,message:`Card inside a Card gives two shadows. Use one Card and split it with headings, or place the Cards side by side.`});return}}}}}},Ja={meta:{type:`suggestion`,docs:{description:`At most one primary button per section.`},schema:[]},create(e){let t=/* @__PURE__ */ new Set([`Card`,`Dialog`,`Drawer`,`section`,`form`,`SettingsSection`]);return{JSXElement(n){let r=n;if(wa(r.openingElement)!==`Button`||!Oa(Ta(r.openingElement,`variant`),`primary`))return;let i=r.parent;for(;i&&!(i.type===`JSXElement`&&t.has(wa(i.openingElement)));)i=i.parent;if(!i)return;let a=e=>{if(!e||typeof e!=`object`)return[];if(Array.isArray(e))return e.flatMap(a);let n=e;if(typeof n.type!=`string`)return[];if(n.type===`ConditionalExpression`){let e=a(n.consequent),t=a(n.alternate);return[...a(n.test),...t.length>e.length?t:e]}let r=[];if(n.type===`JSXElement`){if(n!==i&&t.has(wa(n.openingElement)))return[];wa(n.openingElement)===`Button`&&Oa(Ta(n.openingElement,`variant`),`primary`)&&r.push(n)}for(let e in n)e!==`parent`&&e!==`loc`&&e!==`range`&&r.push(...a(n[e]));return r},o=a(i);o.length>1&&o.includes(r)&&o[0]!==r&&e.report({node:n,message:`A second primary Button in this section. Keep one primary (the main action) and make the others secondary.`})}}}},Ya=/^(確定|確認|好|好的|OK|Ok|ok|是|否|Yes|yes|No|no)$/,Xa={meta:{type:`suggestion`,docs:{description:`Button labels say what happens: 儲存, 刪除 api-gateway, 發布. Not 確定 or OK.`},schema:[]},create(e){return{JSXElement(t){let n=t;if(wa(n.openingElement)!==`Button`)return;let r=ka(n);Ya.test(r)&&e.report({node:t,message:`Button label "{{t}}" does not say what happens. Use the verb of the action instead, e.g. 儲存, 刪除, 送出, 確認刪除.`,data:{t:r}})}}}},Za={meta:{type:`problem`,docs:{description:`A danger Button is confirmed: pass confirm, or confirmed inside the confirm dialog.`},schema:[]},create(e){return{JSXOpeningElement(t){let n=t;wa(n)===`Button`&&Oa(Ta(n,`variant`),`danger`)&&!Ta(n,`confirm`)&&!Ta(n,`confirmed`)&&e.report({node:t,message:`Danger Button without confirmation. Add confirm={{ title: "刪除 …?" }}, or confirmed when it is the button inside the confirm Dialog.`})}}}},Qa=/^(padding|margin|inset|scrollPadding|scrollMargin)(Top|Right|Bottom|Left|Inline|Block|InlineStart|InlineEnd|BlockStart|BlockEnd)?$|^(gap|rowGap|columnGap|fontSize|borderRadius|border(Top|Bottom|Start|End)(Left|Right|Start|End)Radius|boxShadow|fontFamily)$/,$a=[[/^font[sS]ize$/,`var(--text-body) or cssVar("text-small") (text-mini, text-small, text-body, text-title, text-h4…), or Tailwind text-small`],[/[rR]adius$/,`var(--radius-md) or cssVar("radius-sm") (radius-xs, -sm, -md, -lg, -full), or Tailwind rounded-md`],[/^boxShadow$/,`var(--shadow-card) or cssVar("shadow-overlay"), or Tailwind shadow-card`],[/^fontFamily$/,`var(--font-sans) or var(--font-mono), or Tailwind font-sans / font-mono`],[/./,`var(--space-4) or cssVar("space-4") (space-1 4 px to space-12 48 px), or Tailwind p-4 / gap-2`]],eo=e=>($a.find(([t])=>t.test(e))??$a[$a.length-1])[1],to=/(^|[^\w-])\d*\.?\d+(px|rem|em)\b/,G=/^(0|auto|none|inherit|initial|unset|revert|normal|currentColor|transparent)$/i,no=e=>{let t=e;for(let e=0;e<3;e++)t=t.replace(/var\([^()]*(\([^()]*\)[^()]*)*\)/g,``);return t},ro=(e,t)=>{if(typeof t==`number`)return t!==0;if(typeof t!=`string`)return!1;let n=t.trim();if(!n||G.test(n))return!1;let r=no(n).trim();return e===`fontFamily`||e===`boxShadow`?r!==``&&!G.test(r):to.test(r)},io=/^-?(p[xytrblse]?|m[xytrblse]?|gap(?:-[xy])?|space-[xy]|text|rounded(?:-[trblse]{1,2})?|shadow|font|leading|tracking)-\[([^\]]+)\]$/,ao=e=>{let t=io.exec(e);if(!t)return!1;let n=t[2];return/^(var\(|--|#|rgba?\(|hsla?\(|oklch\(|color:)/.test(n)||/var\(--/.test(n)&&!to.test(no(n))?!1:t[1]===`font`||t[1]===`shadow`||to.test(n.replace(/_/g,` `))||/^\d*\.?\d+$/.test(n)},oo={"no-raw-color":Ua,"no-tailwind-defaults":Ha,"no-native-controls":Ka,"no-nested-card":qa,"one-primary-button":Ja,"verb-labels":Xa,"danger-confirm":Za,"no-raw-size":{meta:{type:`suggestion`,docs:{description:`Spacing, type sizes, font families, radii and shadows come from tokens, not raw px values.`},schema:[]},create(e){let t=(t,n,r)=>e.report({node:t,message:`{{k}}: {{v}} is a raw value. Use a token: {{hint}}.`,data:{k:n,v:r.slice(0,40),hint:eo(n)}});return{'JSXAttribute[name.name="style"] Literal'(e){let n=e.parent;for(let t=e;n&&n.type!==`Property`;t=n,n=n.parent){let e=n;if(!(e.type===`ConditionalExpression`&&e.test!==t||[`LogicalExpression`,`TSAsExpression`,`TSSatisfiesExpression`,`TSNonNullExpression`,`UnaryExpression`].includes(e.type)))return}if(!n)return;let r=n;if(r.key===e||r.computed)return;let i=String(r.key?.name??r.key?.value??``);if(!Qa.test(i))return;let a=va(e);ro(i,a)&&t(e,i,String(a))},'JSXAttribute[name.name="style"] Property > TemplateLiteral'(e){let n=e.parent,r=String(n.key?.name??n.key?.value??``);if(!Qa.test(r))return;let i=e.quasis.map(e=>e.value.cooked??``).join(` `);(r===`fontFamily`||r===`boxShadow`?ro(r,i.replace(/\s+/g,` `)):to.test(no(i)))&&t(e,r,i.trim())},...Va((t,n)=>{for(let r of Ba(n))ao(r)&&e.report({node:t,message:`{{c}} is an arbitrary value. Use a token class: p-4, gap-2, text-small, rounded-md, shadow-card, font-mono (or [var(--…)]).`,data:{c:r}})})}}}},so={meta:{name:ha,version:ga},rules:oo,configs:{}};so.configs.recommended={name:`@seanyeh77/ui/recommended`,files:[`**/*.{jsx,tsx}`],plugins:{ui:so},languageOptions:{parser:_a.default,parserOptions:{ecmaFeatures:{jsx:!0}}},rules:{"ui/no-raw-color":`error`,"ui/no-tailwind-defaults":`error`,"ui/no-native-controls":`error`,"ui/no-nested-card":`error`,"ui/danger-confirm":`error`,"ui/no-raw-size":`warn`,"ui/one-primary-button":`warn`,"ui/verb-labels":`warn`}};export{so as default,oo as rules};
551
+ See also https://github.com/typescript-eslint/typescript-eslint/issues/10940 for tracking typescript-eslint's support for TS >=7.1`),Error(`typescript-eslint does not support TS 7.0.`);var c=fa();Object.defineProperty(e,"parse",{enumerable:!0,get:function(){return c.parse}}),Object.defineProperty(e,"parseForESLint",{enumerable:!0,get:function(){return c.parseForESLint}});var l=da();Object.defineProperty(e,"clearCaches",{enumerable:!0,get:function(){return l.clearCaches}}),Object.defineProperty(e,"createProgram",{enumerable:!0,get:function(){return l.createProgram}}),Object.defineProperty(e,"withoutProjectParserOptions",{enumerable:!0,get:function(){return l.withoutProjectParserOptions}}),e.version=pa().version,e.meta={name:`typescript-eslint/parser`,version:e.version}})),ha=`@seanyeh77/eslint-plugin-ui`,ga=`0.53.0`,_a=/* @__PURE__ */ f(ma(),1);const va=e=>e.value,ya=/#[0-9a-fA-F]{3,8}\b|\brgba?\(|\bhsla?\(|\boklch\(/,ba=/url\(\s*['"]?#[^)]*\)/g,xa=/^(black|white|red|green|blue|yellow|orange|purple|pink|gray|grey|brown|cyan|magenta|navy|teal|maroon|olive|lime|aqua|fuchsia|silver|gold|indigo|violet|crimson|tomato|coral|salmon|khaki|beige|ivory|lavender|tan|darkgray|darkgrey|lightgray|lightgrey|darkblue|lightblue|darkred|darkgreen|lightgreen)$/i,Sa=/color|background|fill|stroke|border|outline|shadow/i,Ca=/-\[(#|rgba?\(|hsla?\(|oklch\()/;function wa(e){let t=e.name;return t.type===`JSXIdentifier`?t.name??``:t.type===`JSXMemberExpression`?t.property?.name??``:``}function Ta(e,t){return e.attributes.find(e=>e.type===`JSXAttribute`&&e.name?.name===t)}function Ea(e){return e?e.type===`Literal`?[e.value]:e.type===`ConditionalExpression`?[...Ea(e.consequent),...Ea(e.alternate)]:e.type===`LogicalExpression`?e.operator===`&&`?Ea(e.right):[...Ea(e.left),...Ea(e.right)]:e.type===`TSAsExpression`||e.type===`TSSatisfiesExpression`||e.type===`TSNonNullExpression`?Ea(e.expression):[]:[]}function Da(e){return e?e.value?e.value.type===`Literal`?[e.value.value]:e.value.type===`JSXExpressionContainer`?Ea(e.value.expression):[]:[!0]:[]}const Oa=(e,t)=>Da(e).includes(t);function ka(e){return e.children.map(e=>{let t=e;return t.type===`JSXText`?t.value??``:t.type===`JSXExpressionContainer`&&t.expression?.type===`Literal`?String(t.expression.value):`\0`}).join(``).trim()}const Aa=/* @__PURE__ */ RegExp(`^(bg|text|border(?:-[trblxyse])?|ring(?:-offset)?|inset-ring|outline|divide(?:-[xy])?|fill|stroke|from|via|to|placeholder|decoration|caret|accent|shadow|inset-shadow|drop-shadow|text-shadow)-(?:(?:slate|gray|zinc|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(?:50|[1-9]00|950)|white|black)(?:/(?:[\\d.]+|\\[[^\\]]+\\]|\\([^)]+\\)))?$`),ja=/^rounded(?:-[trblse]{1,2})?(?:-(?:xs|xl|2xl|3xl|4xl))?$/,Ma=/^(?:shadow|drop-shadow|inset-shadow)(?:-(?:2xs|xs|md|lg|xl|2xl|inner))?$/,Na=`cn|clsx|cx|cva|twMerge|twJoin|tv|classnames`,Pa=e=>{for(let t=e.parent;t;t=t.parent){let e=t;if(e.type===`JSXAttribute`)return e.name?.name===`className`||e.name?.name===`class`}return!1},Fa=RegExp(`^(${Na})$`),Ia=e=>{let t;for(let n=e,r=e.parent;r;n=r,r=r.parent){let e=r;if(e.type===`JSXAttribute`)return e.name?.name===`className`||e.name?.name===`class`;if(e.type===`CallExpression`)return Fa.test(e.callee?.name??``);if(e.type===`BinaryExpression`||e.type===`SwitchCase`||e.type===`MemberExpression`&&e.computed&&e.property===n)return!1;if(e.type===`Property`&&e.key===n)return La(r);if(e.type===`Property`){let n=Ra(e.key);if(t??=n,n===`defaultVariants`||(n===`compoundVariants`||n===`compoundSlots`)&&t!==`class`&&t!==`className`)return!1}}return!1},La=e=>{let t=e.parent;if(t?.type!==`ObjectExpression`)return!1;let n=t.parent;for(;n?.type===`ArrayExpression`;)n=n.parent;return n?.type===`CallExpression`&&Fa.test(n.callee?.name??``)},Ra=e=>{let t=e;return t?.type===`Identifier`?t.name:typeof t?.value==`string`?t.value:void 0},za={text:`text-ink, text-ink-muted, text-accent-text, text-danger-text, text-on-accent`,bg:`bg-surface, bg-surface-sub, bg-accent, bg-accent-soft, bg-danger-soft`,border:`border-line, border-line-strong, border-accent`},Ba=e=>e.split(/\s+/).filter(Boolean).map(e=>e.slice(e.lastIndexOf(`:`)+1).replace(/^!|!$/g,``));function Va(e){let t=e=>e.value.cooked??``;return{"JSXAttribute[name.name=/^(className|class)$/] Literal"(t){let n=va(t);typeof n==`string`&&Ia(t)&&e(t,n)},"JSXAttribute[name.name=/^(className|class)$/] TemplateElement"(n){Ia(n)&&e(n,t(n))},[`CallExpression[callee.name=/^(${Na})$/] TemplateElement`](n){!Pa(n)&&Ia(n)&&e(n,t(n))},[`CallExpression[callee.name=/^(${Na})$/] Literal`](t){if(Pa(t))return;let n=va(t);typeof n==`string`&&Ia(t)&&e(t,n)}}}const Ha={meta:{type:`suggestion`,docs:{description:`Disallow Tailwind's default palette, radii and shadows: use the design system's token classes.`},schema:[]},create(e){return Va((t,n)=>{for(let r of Ba(n)){let n=Aa.exec(r);if(n){let i=n[1].startsWith(`border`)?`border`:n[1];e.report({node:t,message:`{{c}} is Tailwind's palette, not a design-system color. Use a token class: {{hint}}.`,data:{c:r,hint:za[i]??`${n[1]}-ink, ${n[1]}-accent, ${n[1]}-line`}})}else ja.test(r)?e.report({node:t,message:`{{c}} is not a design-system radius. Use rounded-sm, rounded-md or rounded-lg.`,data:{c:r}}):Ma.test(r)&&e.report({node:t,message:`{{c}} is not a design-system shadow. Use shadow-card, shadow-overlay or shadow-sm.`,data:{c:r}})}})}},Ua={meta:{type:`problem`,docs:{description:`Colors come from tokens: var(--ink) or cssVar("ink"), never a hex, rgb() or hsl() value.`},schema:[]},create(e){let t=(t,n,r=``)=>{(ya.test(n.replace(ba,``))||Sa.test(r)&&xa.test(n.trim()))&&e.report({node:t,message:`Hard-coded color "{{v}}". Use a token: var(--ink-muted) in CSS, cssVar("ink-muted") from @seanyeh77/tokens in style props, or a component prop.`,data:{v:n.slice(0,40)}})};return{'JSXAttribute[name.name="style"] Literal'(e){let n=va(e);if(typeof n!=`string`)return;let r=e.parent,i=!0;for(let t=e;r&&r.type!==`Property`;t=r,r=r.parent){let e=r;if(e.type===`MemberExpression`&&e.computed&&e.property===t)return;e.type===`ConditionalExpression`&&e.test!==t||[`LogicalExpression`,`TSAsExpression`,`TSSatisfiesExpression`,`TSNonNullExpression`].includes(e.type)||(i=!1)}if(!r)return;let a=r.key;a!==e&&t(e,n,i?String(a?.name??a?.value??``):``)},"JSXAttribute[name.name=/^(className|class)$/] Literal"(t){let n=va(t);typeof n==`string`&&Ca.test(n)&&e.report({node:t,message:`Arbitrary color in "{{v}}". Use the token classes of @seanyeh77/tokens/tailwind.css: bg-surface, text-ink-muted.`,data:{v:n.slice(0,40)}})},'JSXAttribute[name.name="style"] Property > TemplateLiteral > TemplateElement'(e){t(e,String(va(e).raw))},"JSXAttribute[name.name=/^(fill|stroke|color|stopColor|floodColor)$/] Literal"(e){let n=va(e);typeof n==`string`&&t(e,n,`color`)}}}},Wa={select:`Select (or MultiSelect)`,table:`DataTable`,dialog:`Dialog`,progress:`ProgressBar`,textarea:`TextArea`,button:`Button (or IconButton for an icon alone)`,a:`Link`},Ga={"":`TextField`,text:`TextField`,email:`TextField type="email"`,password:`TextField type="password"`,number:`TextField type="number"`,tel:`TextField type="tel"`,url:`TextField type="url"`,range:`TextField type="number" or SegmentedControl`,checkbox:`Checkbox (or Switch for an on/off setting)`,radio:`RadioGroup`,date:`DatePicker`,search:`SearchField`,file:`FileUpload for a drop area, or useFilePicker to open the picker from a button or menu item`,color:`AccentPicker`,submit:`Button`,button:`Button`,reset:`Button`},Ka={meta:{type:`problem`,docs:{description:`Use the design-system component instead of a native control it replaces.`},schema:[{type:`object`,properties:{allow:{type:`array`,items:{type:`string`},description:`Native tags to allow, e.g. ["a"] when links come from a router.`}},additionalProperties:!1}]},create(e){let t=new Set((e.options[0]?.allow??[]).map(e=>e.toLowerCase()));return{JSXOpeningElement(n){let r=n;if(r.name.type!==`JSXIdentifier`)return;let i=wa(r);if(!t.has(i)&&!Da(Ta(r,`className`)).some(e=>typeof e==`string`&&/(^|\s)ui-[a-z]/.test(e))&&(Wa[i]&&e.report({node:n,message:`Native <{{n}}>: use {{c}} from @seanyeh77/ui.`,data:{n:i,c:Wa[i]}}),i===`input`)){let i=Ta(r,`hidden`);if(i&&Da(i).length&&Da(i).every(e=>e===!0||e===``||e===`hidden`))return;let a=Ta(r,`type`),o=a?Da(a):[``];for(let r of new Set(o))typeof r==`string`&&Ga[r.toLowerCase()]&&!t.has(`input[type=${r||`text`}]`)&&e.report({node:n,message:`<input{{t}}>: use {{c}} from @seanyeh77/ui.`,data:{t:r?` type="${r}"`:``,c:Ga[r.toLowerCase()]}})}}}}},qa={meta:{type:`problem`,docs:{description:`No Card inside a Card: one shadow per block.`},schema:[]},create(e){return{JSXElement(t){let n=t;if(wa(n.openingElement)===`Card`){for(let r=n.parent;r;r=r.parent)if(r.type===`JSXElement`&&wa(r.openingElement)===`Card`){e.report({node:t,message:`Card inside a Card gives two shadows. Use one Card and split it with headings, or place the Cards side by side.`});return}}}}}},Ja={meta:{type:`suggestion`,docs:{description:`At most one primary button per section.`},schema:[]},create(e){let t=/* @__PURE__ */ new Set([`Card`,`Dialog`,`Drawer`,`section`,`form`,`SettingsSection`]);return{JSXElement(n){let r=n;if(wa(r.openingElement)!==`Button`||!Oa(Ta(r.openingElement,`variant`),`primary`))return;let i=r.parent;for(;i&&!(i.type===`JSXElement`&&t.has(wa(i.openingElement)));)i=i.parent;if(!i)return;let a=e=>{if(!e||typeof e!=`object`)return[];if(Array.isArray(e))return e.flatMap(a);let n=e;if(typeof n.type!=`string`)return[];if(n.type===`ConditionalExpression`){let e=a(n.consequent),t=a(n.alternate);return[...a(n.test),...t.length>e.length?t:e]}let r=[];if(n.type===`JSXElement`){if(n!==i&&t.has(wa(n.openingElement)))return[];wa(n.openingElement)===`Button`&&Oa(Ta(n.openingElement,`variant`),`primary`)&&r.push(n)}for(let e in n)e!==`parent`&&e!==`loc`&&e!==`range`&&r.push(...a(n[e]));return r},o=a(i);o.length>1&&o.includes(r)&&o[0]!==r&&e.report({node:n,message:`A second primary Button in this section. Keep one primary (the main action) and make the others secondary.`})}}}},Ya=/^(確定|確認|好|好的|OK|Ok|ok|是|否|Yes|yes|No|no)$/,Xa={meta:{type:`suggestion`,docs:{description:`Button labels say what happens: 儲存, 刪除 api-gateway, 發布. Not 確定 or OK.`},schema:[]},create(e){return{JSXElement(t){let n=t;if(wa(n.openingElement)!==`Button`)return;let r=ka(n);Ya.test(r)&&e.report({node:t,message:`Button label "{{t}}" does not say what happens. Use the verb of the action instead, e.g. 儲存, 刪除, 送出, 確認刪除.`,data:{t:r}})}}}},Za={meta:{type:`problem`,docs:{description:`A danger Button is confirmed: pass confirm, or confirmed inside the confirm dialog.`},schema:[]},create(e){return{JSXOpeningElement(t){let n=t;wa(n)===`Button`&&Oa(Ta(n,`variant`),`danger`)&&!Ta(n,`confirm`)&&!Ta(n,`confirmed`)&&e.report({node:t,message:`Danger Button without confirmation. Add confirm={{ title: "刪除 …?" }}, or confirmed when it is the button inside the confirm Dialog.`})}}}},Qa=/^(padding|margin|inset|scrollPadding|scrollMargin)(Top|Right|Bottom|Left|Inline|Block|InlineStart|InlineEnd|BlockStart|BlockEnd)?$|^(gap|rowGap|columnGap|fontSize|borderRadius|border(Top|Bottom|Start|End)(Left|Right|Start|End)Radius|boxShadow|fontFamily)$/,$a=[[/^font[sS]ize$/,`var(--text-body) or cssVar("text-small") (text-mini, text-small, text-body, text-title, text-h4…), or Tailwind text-small`],[/[rR]adius$/,`var(--radius-md) or cssVar("radius-sm") (radius-xs, -sm, -md, -lg, -full), or Tailwind rounded-md`],[/^boxShadow$/,`var(--shadow-card) or cssVar("shadow-overlay"), or Tailwind shadow-card`],[/^fontFamily$/,`var(--font-sans) or var(--font-mono), or Tailwind font-sans / font-mono`],[/./,`var(--space-4) or cssVar("space-4") (space-1 4 px to space-12 48 px), or Tailwind p-4 / gap-2`]],eo=e=>($a.find(([t])=>t.test(e))??$a[$a.length-1])[1],to=/(^|[^\w-])\d*\.?\d+(px|rem|em)\b/,G=/^(0|auto|none|inherit|initial|unset|revert|normal|currentColor|transparent)$/i,no=e=>{let t=e;for(let e=0;e<3;e++)t=t.replace(/var\([^()]*(\([^()]*\)[^()]*)*\)/g,``);return t},ro=(e,t)=>{if(typeof t==`number`)return t!==0;if(typeof t!=`string`)return!1;let n=t.trim();if(!n||G.test(n))return!1;let r=no(n).trim();return e===`fontFamily`||e===`boxShadow`?r!==``&&!G.test(r):to.test(r)},io=/^-?(p[xytrblse]?|m[xytrblse]?|gap(?:-[xy])?|space-[xy]|text|rounded(?:-[trblse]{1,2})?|shadow|font|leading|tracking)-\[([^\]]+)\]$/,ao=e=>{let t=io.exec(e);if(!t)return!1;let n=t[2];return/^(var\(|--|#|rgba?\(|hsla?\(|oklch\(|color:)/.test(n)||/var\(--/.test(n)&&!to.test(no(n))?!1:t[1]===`font`||t[1]===`shadow`||to.test(n.replace(/_/g,` `))||/^\d*\.?\d+$/.test(n)},oo={meta:{type:`suggestion`,docs:{description:`Spacing, type sizes, font families, radii and shadows come from tokens, not raw px values.`},schema:[]},create(e){let t=(t,n,r)=>e.report({node:t,message:`{{k}}: {{v}} is a raw value. Use a token: {{hint}}.`,data:{k:n,v:r.slice(0,40),hint:eo(n)}});return{'JSXAttribute[name.name="style"] Literal'(e){let n=e.parent;for(let t=e;n&&n.type!==`Property`;t=n,n=n.parent){let e=n;if(!(e.type===`ConditionalExpression`&&e.test!==t||[`LogicalExpression`,`TSAsExpression`,`TSSatisfiesExpression`,`TSNonNullExpression`,`UnaryExpression`].includes(e.type)))return}if(!n)return;let r=n;if(r.key===e||r.computed)return;let i=String(r.key?.name??r.key?.value??``);if(!Qa.test(i))return;let a=va(e);ro(i,a)&&t(e,i,String(a))},'JSXAttribute[name.name="style"] Property > TemplateLiteral'(e){let n=e.parent,r=String(n.key?.name??n.key?.value??``);if(!Qa.test(r))return;let i=e.quasis.map(e=>e.value.cooked??``).join(` `);(r===`fontFamily`||r===`boxShadow`?ro(r,i.replace(/\s+/g,` `)):to.test(no(i)))&&t(e,r,i.trim())},...Va((t,n)=>{for(let r of Ba(n))ao(r)&&e.report({node:t,message:`{{c}} is an arbitrary value. Use a token class: p-4, gap-2, text-small, rounded-md, shadow-card, font-mono (or [var(--…)]).`,data:{c:r}})})}}};function so(e){let t=Ta(e,`style`),n=t?.value?.type===`JSXExpressionContainer`?t.value.expression:void 0;return n?.type===`ObjectExpression`?(n.properties??[]).map(e=>String(e.key?.name??e.key?.value??``)):[]}const co=/^(gap|rowGap|margin|marginTop|marginBottom|marginBlock|marginBlockStart|marginBlockEnd)$/,lo=/^(gap|gap-y|space-y|m|my|mt|mb)-/,uo=/* @__PURE__ */ new Set([`Card`,`Alert`,`KpiCard`,`DataTable`,`SettingsSection`]),fo={"no-raw-color":Ua,"no-tailwind-defaults":Ha,"no-native-controls":Ka,"no-nested-card":qa,"one-primary-button":Ja,"verb-labels":Xa,"danger-confirm":Za,"no-raw-size":oo,"no-custom-block-gap":{meta:{type:`suggestion`,docs:{description:`Blocks on a page are stacked by Page and Grid, not by a wrapper or margin of their own.`},schema:[]},create(e){return{JSXElement(t){let n=t,r=n.parent;for(;r&&r.type!==`JSXElement`;)r=r.parent;if(!r||![`Page`,`Grid`].includes(wa(r.openingElement)))return;let i=wa(n.openingElement);if(!(/^[a-z]/.test(i)||uo.has(i)))return;let a=Da(Ta(n.openingElement,`className`)).filter(e=>typeof e==`string`),o=[...so(n.openingElement).filter(e=>co.test(e)),...a.flatMap(e=>e.split(/\s+/)).filter(e=>lo.test(e))];o.length&&e.report({node:t,message:`{{what}} sets its own spacing ({{bad}}) between blocks in a {{parent}}, so these blocks sit at a different distance from the rest of the page. Stack them with Page (a Page per column inside a Grid): blocks are then always block-gap apart.`,data:{what:/^[a-z]/.test(i)?`A <${i}> wrapper`:i,bad:o.slice(0,3).join(`, `),parent:wa(r.openingElement)}})}}}}},po={meta:{name:ha,version:ga},rules:fo,configs:{}};po.configs.recommended={name:`@seanyeh77/ui/recommended`,files:[`**/*.{jsx,tsx}`],plugins:{ui:po},languageOptions:{parser:_a.default,parserOptions:{ecmaFeatures:{jsx:!0}}},rules:{"ui/no-raw-color":`error`,"ui/no-tailwind-defaults":`error`,"ui/no-native-controls":`error`,"ui/no-nested-card":`error`,"ui/danger-confirm":`error`,"ui/no-custom-block-gap":`error`,"ui/no-raw-size":`warn`,"ui/one-primary-button":`warn`,"ui/verb-labels":`warn`}};export{po as default,fo as rules};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seanyeh77/eslint-plugin-ui",
3
- "version": "0.52.1",
3
+ "version": "0.53.0",
4
4
  "description": "ESLint rules for SeanYeh's design system: token colors only, design-system components instead of native controls, no card in a card, one primary button, verb labels.",
5
5
  "license": "MIT",
6
6
  "author": "Hsiu-An Yeh",