@via-ds/stylelint-plugin 0.0.1-canary.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 ADDED
@@ -0,0 +1,62 @@
1
+ # @via-ds/stylelint-plugin
2
+
3
+ Stylelint plugin for the Via Design System.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add -D @via-ds/stylelint-plugin stylelint
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Using the Recommended Config
14
+
15
+ The easiest way to get started is to extend the recommended configuration:
16
+
17
+ ```js
18
+ // stylelint.config.mjs
19
+ export default {
20
+ extends: ['@via-ds/stylelint-plugin/recommended'],
21
+ };
22
+ ```
23
+
24
+ This enables all recommended rules with sensible defaults.
25
+
26
+ ### Manual Configuration
27
+
28
+ You can also configure the plugin manually:
29
+
30
+ ```js
31
+ // stylelint.config.mjs
32
+ export default {
33
+ plugins: ['@via-ds/stylelint-plugin'],
34
+ rules: {
35
+ 'via/example-rule': true,
36
+ },
37
+ };
38
+ ```
39
+
40
+ ## Rules
41
+
42
+ | Rule | Description |
43
+ | ------------------ | ---------------------------------------------------- |
44
+ | `via/example-rule` | Example rule that reports selectors containing "foobar" |
45
+
46
+ ---
47
+
48
+ ## Creating New Rules
49
+
50
+ 1. Create a new file in `src/rules/` (using `example-rule.ts` as a template)
51
+ 2. Register the rule in `src/rules/index.ts`
52
+
53
+ The `createRule` helper provides walk callbacks for different CSS node types:
54
+
55
+ - `walkRules` - Selectors (`.class`, `#id`)
56
+ - `walkDecls` - Declarations (`property: value`)
57
+ - `walkAtRules` - At-rules (`@media`, `@import`)
58
+ - `walkComments` - CSS comments
59
+
60
+ Each callback receives the node and a context with `messages`, `report()`, and `fix`.
61
+
62
+ For more, see the [Stylelint Plugins documentation](https://stylelint.io/developer-guide/plugins/)
@@ -0,0 +1,4 @@
1
+ import stylelint from "stylelint";
2
+ declare const rulesPlugins: stylelint.Plugin[];
3
+ export default rulesPlugins;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAKlC,QAAA,MAAM,YAAY,oBAEhB,CAAC;AAEH,eAAe,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import e from"stylelint";function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function r(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function o(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach(function(t){r(e,t,o[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))})}return e}function a(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,a,i,l=[],u=!0,c=!1;try{if(a=(r=r.call(e)).next,0===t);else for(;!(u=(n=a.call(r)).done)&&(l.push(n.value),l.length!==t);u=!0);}catch(e){c=!0,o=e}finally{try{if(!u&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(c)throw o}}return l}}(e,r)||function(e,r){if(e){if("string"==typeof e)return t(e,r);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var i=e.utils,l=i.report,u=i.ruleMessages,c=i.validateOptions;function s(e){var t=e.meta,r=e.ruleName,n=e.walkAtRules,a=e.walkComments,i=e.walkDecls,s=e.walkRoot,f=e.walkRules,m="".concat("via","/").concat(r),p=u(m,e.messages),b=function(e,t,r){return function(t,u){var b;if(c(u,m,{actual:e,possible:[!0]})){var g={messages:p,fix:null!==(b=null==r?void 0:r.fix)&&void 0!==b&&b,report:function(e){l(o(o({},e),{},{result:u,ruleName:m}))}};s&&s(t,g),f&&t.walkRules(function(e){return f(e,g)}),i&&t.walkDecls(function(e){return i(e,g)}),n&&t.walkAtRules(function(e){return n(e,g)}),a&&t.walkComments(function(e){return a(e,g)})}}};return b.ruleName=r,b.messages=p,t&&(b.meta=t),b}var f=s({ruleName:"example-rule",messages:{rejected:function(e){return'Example rule violation in selector "'.concat(e,'"')}},meta:{url:"https://github.com/10gen/lg/blob/main/packages/tools/stylelint-plugin/README.md"},walkRules:function(e,t){var r=t.messages,n=t.report,o=e.selector;o.includes("foobar")&&n({message:r.rejected(o),node:e,word:o})}}),m=/\battr\s*\(/i,p=s({ruleName:"no-attr-function",messages:{rejected:function(e){return'Unexpected "attr()" in "'.concat(e,'". The attr() function has limited browser support outside of the "content" property (https://caniuse.com/?search=attr()).')}},meta:{url:"https://github.com/10gen/lg/blob/main/packages/tools/stylelint-plugin/README.md"},walkDecls:function(e,t){var r=t.messages,n=t.report;"content"!==e.prop&&m.test(e.value)&&n({message:r.rejected(e.prop),node:e,word:"attr("})}}),b=r(r({},f.ruleName,f),p.ruleName,p),g=Object.entries(b).map(function(t){var r=a(t,2),n=r[0],o=r[1];return e.createPlugin("".concat("via","/").concat(n),o)});export{g as default};
@@ -0,0 +1,3 @@
1
+ /** Namespace prefix for rule IDs in config and warning output (e.g. `via/example-rule`). */
2
+ export declare const PLUGIN_NAMESPACE = "via";
3
+ //# sourceMappingURL=plugin-namespace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-namespace.d.ts","sourceRoot":"","sources":["../src/plugin-namespace.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,eAAO,MAAM,gBAAgB,QAAQ,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { Config } from "stylelint";
2
+ /**
3
+ * Recommended Via stylelint configuration.
4
+ *
5
+ * Enforces design token usage by prohibiting:
6
+ * - Named colors and hex values (use CSS variables instead)
7
+ * - Hard-coded spacing values (use token variables instead)
8
+ *
9
+ * Usage:
10
+ * ```js
11
+ * // stylelint.config.mjs
12
+ * export default {
13
+ * extends: ['@via-ds/stylelint-plugin/recommended'],
14
+ * };
15
+ * ```
16
+ */
17
+ declare const recommended: Config;
18
+ export default recommended;
19
+ //# sourceMappingURL=recommended.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recommended.d.ts","sourceRoot":"","sources":["../src/recommended.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC;;;;;;;;;;;;;;GAcG;AACH,QAAA,MAAM,WAAW,EAAE,MAMlB,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -0,0 +1 @@
1
+ var a={plugins:["@via-ds/stylelint-plugin"],rules:{"via/example-rule":!0,"via/no-attr-function":!0}};export{a as default};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Example rule that reports any selector containing "foobar".
3
+ *
4
+ * This demonstrates the simplified createRule API where you
5
+ * just provide walk callbacks - no boilerplate required.
6
+ */
7
+ declare const _default: import("stylelint").Rule<true, unknown, {
8
+ rejected: (selector: string) => string;
9
+ }>;
10
+ export default _default;
11
+ //# sourceMappingURL=example-rule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example-rule.d.ts","sourceRoot":"","sources":["../../src/rules/example-rule.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;;yBAKsB,MAAM;;AAJ/B,wBAuBG"}
@@ -0,0 +1,15 @@
1
+ import type { Rule } from "stylelint";
2
+ /**
3
+ * Registry of all Via stylelint rules.
4
+ *
5
+ * To add a new rule:
6
+ * 1. Create a new file in this directory (e.g., `no-invalid-token.ts`)
7
+ * 2. Export the rule function as default
8
+ * 3. Import and add it to this object
9
+ *
10
+ * Rule names will be prefixed with "via/" when registered.
11
+ * Example: A rule named "no-invalid-token" becomes "via/no-invalid-token"
12
+ */
13
+ declare const rules: Record<string, Rule>;
14
+ export default rules;
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAKtC;;;;;;;;;;GAUG;AACH,QAAA,MAAM,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAG/B,CAAC;AAEF,eAAe,KAAK,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Disallows `attr()` in CSS declaration values due to limited browser support.
3
+ *
4
+ * While `attr()` works in the `content` property across all browsers,
5
+ * its use on other CSS properties (CSS Values Level 5) lacks broad support.
6
+ * This rule flags all usage to ensure cross-browser compatibility.
7
+ *
8
+ * @see https://caniuse.com/?search=attr()
9
+ */
10
+ declare const _default: import("stylelint").Rule<true, unknown, {
11
+ rejected: (property: string) => string;
12
+ }>;
13
+ export default _default;
14
+ //# sourceMappingURL=no-attr-function.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-attr-function.d.ts","sourceRoot":"","sources":["../../src/rules/no-attr-function.ts"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;;yBAKsB,MAAM;;AAJ/B,wBAuBG"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=no-attr-function.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-attr-function.spec.d.ts","sourceRoot":"","sources":["../../src/rules/no-attr-function.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Re-export stylelint types for convenience
3
+ */
4
+ export type { Rule, RuleContext, RuleMessages, RuleMeta } from "stylelint";
5
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,YAAY,EAAE,IAAI,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,79 @@
1
+ import type { AtRule, Comment, Declaration, Root, Rule as CssRule } from "postcss";
2
+ import type { PostcssResult, Problem, ProblemLocation, Rule, RuleMessages, RuleMeta } from "stylelint";
3
+ import stylelint from "stylelint";
4
+ declare const report: (problem: Problem) => void, ruleMessages: <T extends RuleMessages, R extends { [K in keyof T]: T[K]; }>(ruleName: string, messages: T) => R, validateOptions: (result: PostcssResult, ruleName: string, ...optionDescriptions: stylelint.RuleOptions[]) => boolean;
5
+ /**
6
+ * Problem report type for the `report` function.
7
+ * Excludes `result` and `ruleName` which are automatically
8
+ * provided by the createRule wrapper.
9
+ */
10
+ export type ReportProblem = Omit<Problem, "result" | "ruleName" | keyof ProblemLocation> & ProblemLocation;
11
+ /**
12
+ * Context passed to walk callbacks.
13
+ */
14
+ export interface WalkContext<M extends RuleMessages = RuleMessages> {
15
+ /** Rule messages with ruleName suffix applied */
16
+ messages: M;
17
+ /** Whether autofix is enabled */
18
+ fix: boolean;
19
+ /**
20
+ * Report a problem. `result` and the namespaced rule id (`via/...`) are automatically provided.
21
+ */
22
+ report: (problem: ReportProblem) => void;
23
+ }
24
+ /**
25
+ * Generic walk callback type for PostCSS nodes.
26
+ */
27
+ export type WalkCallback<N, M extends RuleMessages> = (node: N, context: WalkContext<M>) => void;
28
+ /**
29
+ * Rule definition with simplified walk callbacks.
30
+ * Just provide the walk callback(s) you need - no boilerplate required.
31
+ */
32
+ export interface RuleDefinition<M extends RuleMessages = RuleMessages> {
33
+ /** The rule name (without namespace prefix) */
34
+ ruleName: string;
35
+ /** Rule messages object */
36
+ messages: M;
37
+ /** Optional rule metadata */
38
+ meta?: RuleMeta;
39
+ /** Walk CSS rules (selectors) */
40
+ walkRules?: WalkCallback<CssRule, M>;
41
+ /** Walk declarations (property: value pairs) */
42
+ walkDecls?: WalkCallback<Declaration, M>;
43
+ /** Walk at-rules (@media, @import, etc.) */
44
+ walkAtRules?: WalkCallback<AtRule, M>;
45
+ /** Walk comments */
46
+ walkComments?: WalkCallback<Comment, M>;
47
+ /** Process the root node directly (for custom traversal) */
48
+ walkRoot?: WalkCallback<Root, M>;
49
+ }
50
+ /**
51
+ * Factory function to create a stylelint rule with minimal boilerplate.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { createRule } from "../utils/create-rule.js";
56
+ *
57
+ * export default createRule({
58
+ * ruleName: "no-foobar-selector",
59
+ * messages: {
60
+ * rejected: (selector) => `Unexpected "foobar" in selector "${selector}"`,
61
+ * },
62
+ * meta: {
63
+ * url: "https://example.com/rules/no-foobar-selector",
64
+ * },
65
+ * walkRules(ruleNode, { report, messages }) {
66
+ * if (ruleNode.selector.includes("foobar")) {
67
+ * report({
68
+ * message: messages.rejected(ruleNode.selector),
69
+ * node: ruleNode,
70
+ * word: ruleNode.selector,
71
+ * });
72
+ * }
73
+ * },
74
+ * });
75
+ * ```
76
+ */
77
+ export declare function createRule<M extends RuleMessages = RuleMessages>(definition: RuleDefinition<M>): Rule<true, unknown, M>;
78
+ export { report, ruleMessages, validateOptions };
79
+ //# sourceMappingURL=create-rule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AO,EAAE,CAAC,CAAC,CAAC;IAErC,gDAAgD;IAChD,SAAS,CAAC,EAAE,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IAEzC,4CAA4C;IAC5C,WAAW,CAAC,EAAE,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAEtC,oBAAoB;IACpB,YAAY,CAAC,EAAE,YAAY,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAExC,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,YAAY,GAAG,YAAY,EAC9D,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,GAC5B,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CA0DxB;AAED,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { createRule, report, type ReportProblem, type RuleDefinition, ruleMessages, validateOptions, type WalkContext, } from "./create-rule.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,MAAM,EACN,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,YAAY,EACZ,eAAe,EACf,KAAK,WAAW,GACjB,MAAM,kBAAkB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@via-ds/stylelint-plugin",
3
+ "version": "0.0.1-canary.0",
4
+ "description": "Stylelint plugin for Via Design System",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "type": "module",
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/10gen/via.git",
14
+ "directory": "packages/tools/stylelint-plugin"
15
+ },
16
+ "keywords": [
17
+ "stylelint",
18
+ "stylelint-plugin",
19
+ "stylelint-config",
20
+ "via",
21
+ "mongodb"
22
+ ],
23
+ "license": "Apache-2.0",
24
+ "dependencies": {
25
+ "@via-ds/tokens": "0.0.1-canary.0"
26
+ },
27
+ "devDependencies": {
28
+ "@rollup/plugin-babel": "^6.1.0",
29
+ "@rollup/plugin-node-resolve": "^16.0.3",
30
+ "@rollup/plugin-terser": "^0.4.4",
31
+ "@types/node": "24.1.0",
32
+ "postcss": "^8.0.0",
33
+ "rollup": "4.55.1",
34
+ "rollup-plugin-node-externals": "^8.1.2",
35
+ "rollup-plugin-postcss": "^4.0.2",
36
+ "stylelint": "^17.0.0",
37
+ "typescript": "5.9.3",
38
+ "@via-ds/config": "^0.0.0"
39
+ },
40
+ "peerDependencies": {
41
+ "stylelint": "^16.0.0 || ^17.0.0"
42
+ },
43
+ "files": [
44
+ "dist"
45
+ ],
46
+ "exports": {
47
+ ".": {
48
+ "types": "./dist/index.d.ts",
49
+ "import": "./dist/index.js",
50
+ "default": "./dist/index.js"
51
+ },
52
+ "./recommended": {
53
+ "types": "./dist/recommended.d.ts",
54
+ "import": "./dist/recommended.js",
55
+ "default": "./dist/recommended.js"
56
+ }
57
+ },
58
+ "scripts": {
59
+ "build": "rollup --config ./rollup.config.js",
60
+ "tsc": "tsc --project ./tsconfig.json",
61
+ "test": "vitest run"
62
+ }
63
+ }