{"id":15369803,"url":"https://github.com/electrovir/stylelint-rule-creator","last_synced_at":"2025-10-12T16:07:49.752Z","repository":{"id":47162234,"uuid":"274922670","full_name":"electrovir/stylelint-rule-creator","owner":"electrovir","description":"Create custom stylelint rules with less boilerplate.","archived":false,"fork":false,"pushed_at":"2022-03-25T02:40:23.000Z","size":2515,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-12T16:07:49.256Z","etag":null,"topics":["boilerplate","create","css","jest","less","lint","rule","sass","scss","style","stylelint","test"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/stylelint-rule-creator","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/electrovir.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-25T13:25:49.000Z","updated_at":"2023-08-24T14:34:00.000Z","dependencies_parsed_at":"2022-09-17T16:31:04.520Z","dependency_job_id":null,"html_url":"https://github.com/electrovir/stylelint-rule-creator","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"purl":"pkg:github/electrovir/stylelint-rule-creator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electrovir%2Fstylelint-rule-creator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electrovir%2Fstylelint-rule-creator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electrovir%2Fstylelint-rule-creator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electrovir%2Fstylelint-rule-creator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/electrovir","download_url":"https://codeload.github.com/electrovir/stylelint-rule-creator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/electrovir%2Fstylelint-rule-creator/sbom","scorecard":{"id":372062,"data":{"date":"2025-08-11","repo":{"name":"github.com/electrovir/stylelint-rule-creator","commit":"91e877bc7b2130475eb332b42467f3f7e473717a"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.6,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/26 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":5,"reason":"dependency not pinned by hash detected -- score normalized to 5","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/virmator-tagged-release.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/electrovir/stylelint-rule-creator/virmator-tagged-release.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/virmator-tagged-release.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/electrovir/stylelint-rule-creator/virmator-tagged-release.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/virmator-tagged-release.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/electrovir/stylelint-rule-creator/virmator-tagged-release.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/virmator-tests.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/electrovir/stylelint-rule-creator/virmator-tests.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/virmator-tests.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/electrovir/stylelint-rule-creator/virmator-tests.yml/master?enable=pin","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned","Info:   2 out of   2 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/virmator-tagged-release.yml:1","Warn: no topLevel permission defined: .github/workflows/virmator-tests.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":0,"reason":"Project has not signed or included provenance with any releases.","details":["Warn: release artifact v5.1.0 not signed: https://api.github.com/repos/electrovir/stylelint-rule-creator/releases/62743134","Warn: release artifact v5.1.0 does not have provenance: https://api.github.com/repos/electrovir/stylelint-rule-creator/releases/62743134"],"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 4 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"17 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55","Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-28xr-mwxg-3qc8","Warn: Project is vulnerable to: GHSA-9p95-fxvg-qgq2","Warn: Project is vulnerable to: GHSA-9w5j-4mwv-2wj8","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-18T13:12:11.161Z","repository_id":47162234,"created_at":"2025-08-18T13:12:11.162Z","updated_at":"2025-08-18T13:12:11.162Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279011983,"owners_count":26085039,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["boilerplate","create","css","jest","less","lint","rule","sass","scss","style","stylelint","test"],"created_at":"2024-10-01T13:38:44.940Z","updated_at":"2025-10-12T16:07:49.734Z","avatar_url":"https://github.com/electrovir.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Stylelint Rule Creator\n\n_This is not an official [stylelint](https://stylelint.io) package._\n\n[![tests](https://github.com/electrovir/stylelint-rule-creator/actions/workflows/virmator-tests.yml/badge.svg?branch=master)](https://github.com/electrovir/stylelint-rule-creator/actions/workflows/virmator-tests.yml)\n\n**Create custom stylelint rules with less boilerplate.**\n\nThis package greatly reduces the complexity of creating custom stylelint rules. All that is needed is calling a single function to generate a testable and directly exportable rule to stylelint as a plugin. All the necessary types are also included to keep everything type safe.\n\nThere are two ways of creating a decreased-boilerplate rule with this package. Both export an object which can be directly exported as a `Plugin` for stylelint.\n\n-   There's the opinionated `DefaultRule` created with `createDefaultRule`. `DefaultRule` is very easy to test, automatically generates tests based on those supplied to it, and is much more type safe.\n-   There's the bare-bones `Rule` created with `createRule`. This is less opinionated than `DefaultRule` but requires more checking in the rule and setup for tests.\n\nIf possible, prefer using `DefaultRule` with `createDefaultRule` to have the best experience.\n\n## Installation\n\n```bash\nnpm install stylelint-rule-creator\n```\n\n## `createDefaultRule` Usage\n\nThis is the recommended way of creating a rule.\n\n`createDefaultRule` creates a `DefaultRule` object which greatly reduces boilerplate needed for type checking and testing. Extra tests are automatically generated from the tests you supply. Stricter typing is enforced on `DefaultRule` and its tests.\n\n`DefaultRule` requires that the rule is always enabled with a single option (no secondary options) which is either a boolean or an object, as seen in the following type:\n\n```typescript\nboolean | {\n    mode: DefaultOptionMode;\n    fileExceptions?: string[];\n    lineExceptions?: string[];\n}\n```\n\nThis type can easily be extended to add more properties to the object portion of that format ([which is done in the example `DefaultRule`](https://github.com/electrovir/stylelint-rule-creator/blob/master/src/test/rules/file-name-starts-with/file-name-starts-with.rule.ts)), like so:\n\n```typescript\nimport {DefaultRuleOptions} from 'stylelint-rule-creator';\n\ntype MyCustomRuleOptions = DefaultRuleOptions \u0026 {\n    // note that all values must be either strings or numbers because this will come straight from a stylelint config file\n    anotherProperty: string;\n};\n```\n\nIf more flexibility is needed, use the simpler `createRule` which is explained in a later section.\n\nCreate a `DefaultRule` like so:\n\n```typescript\nimport {DefaultRuleOptions, DefaultOptionMode, createDefaultRule} from 'stylelint-rule-creator';\n\nconst messages = {\n    exampleMessage(input: string) {\n        return `Example message with ${input}`;\n    },\n};\n\nexport const exampleDefaultRule = createDefaultRule\u003ctypeof messages, DefaultRuleOptions\u003e({\n    ruleName: 'my-plugin-name/my-rule-name',\n    messages,\n    defaultOptions: {\n        mode: DefaultOptionMode.REQUIRE,\n    },\n    ruleCallback: (report, messages, {ruleOptions, root}) =\u003e {\n        // whatever your rule does here\n\n        // example:\n        root.walkDecls((decl) =\u003e {\n            if (decl.prop === 'visibility') {\n                report({\n                    message: messages.myMessageName(decl.value),\n                    node: decl,\n                    word: decl.value,\n                });\n            }\n        });\n    },\n});\n```\n\nFor more info, see the [source code here](https://github.com/electrovir/stylelint-rule-creator/blob/master/src/default-rule.ts), which is heavily documented.\n\n[See this file for an example using `createDefaultRule`.](https://github.com/electrovir/stylelint-rule-creator/blob/master/src/test/rules/file-name-starts-with/file-name-starts-with.rule.ts)\n\n### `DefaultRule` Testing\n\nTesting a `DefaultRule` (the output of `createDefaultRule`) is very simple and requires very little boilerplate.\n\n```typescript\nimport {testDefaultRule, DefaultOptionMode} from 'stylelint-rule-creator';\n\ntestDefaultRule({\n    rule: yourRuleHere,\n    pluginPath: 'path/to/plugin/file.js',\n    tests: [\n        {\n            ruleOptions: {\n                mode: DefaultOptionMode.REQUIRE,\n            },\n            description: 'top level description optional',\n            accept: [\n                {\n                    code: 'whatever code here',\n                    description:\n                        'lower level description optional but should exist if top level description does not',\n                },\n            ],\n            reject: [\n                {\n                    code: 'whatever code here',\n                    description:\n                        'lower level description optional but should exist if top level description does not',\n                    message:\n                        'message with rule name must be supplied for rejections (plugin-name/rule-name)',\n                },\n            ],\n        },\n        //... more tests\n    ],\n});\n```\n\nFor more info, see the [default rule test source code here](https://github.com/electrovir/stylelint-rule-creator/blob/master/src/default-rule-test.ts), which is heavily documented.\n\n[See this file for example `DefaultRule` tests.](https://github.com/electrovir/stylelint-rule-creator/blob/master/src/test/rules/file-name-starts-with/file-name-starts-with.test.ts)\n\n## `createRule` Usage\n\nThis creates a basic `Rule` which can be directly exported to stylelint as a plugin just as the above `DefaultRule` can be. `Rule` is much simpler than `DefaultRule` and doesn't provide as many typing or testing benefits. It, however, makes less requirements on your input rule options. For example, this allows primary and secondary options (whereas `DefaultRule` requires all information to be in a singular primary option).\n\nTo create a `Rule`, use the following:\n\n```typescript\nimport {createRule} from 'stylelint-rule-creator';\n\nexport const myExampleRule = createRule({\n    ruleName: 'my-plugin-name/my-rule-name',\n    messages: {\n        myMessageName: (messageInput: string) =\u003e `My message example: ${messageInput}`,\n    },\n    ruleCallback: (report, messages, {primaryOption, root}) =\u003e {\n        // whatever your rule does here\n\n        // example:\n        if (!primaryOption) {\n            // this needs to be checked because the basic createRule function doesn't do any option checking for us\n            return;\n        }\n\n        root.walkDecls((decl) =\u003e {\n            if (decl.prop === 'visibility') {\n                report({\n                    message: messages.myMessageName(decl.value),\n                    node: decl,\n                    word: decl.value,\n                });\n            }\n        });\n    },\n});\n```\n\n[See this file for an example using `createRule`.](https://github.com/electrovir/stylelint-rule-creator/blob/master/src/test/rules/visibility/visibility.rule.ts)\n\n### `Rule` Testing\n\nWhen not using `createDefaultRule`, testing is more verbose and requires more boilerplate.\n\nThis package exports the functionality of the [`stylelint-jest-rule-tester` package](https://www.npmjs.com/package/stylelint-jest-rule-tester) to be used for these testing purposes.\n\n#### Create testRule\n\nIn a central file somewhere, create your `testRule` function by calling `getTestRuleFunction` with a reference to your plugin's main file:\n\n```typescript\nimport {getTestRuleFunction} from 'stylelint-rule-creator';\n\nexport const testRule = getTestRuleFunction({\n    // a plugin must be supplied so that stylelint can find the rule(s) you want to test\n    linterOptions: {config: {plugins: ['./dist/index.js']}},\n});\n```\n\nIn this example, `dist/index.js` should be the file which is exporting your rules as its default export. See [this plugin test file](https://github.com/electrovir/stylelint-rule-creator/blob/master/src/test/test-plugin.ts) as an example of this.\n\n#### Use testRule\n\nThen, in your rule's test file, import and call `testRule` like so:\n\n```typescript\nimport {exampleRule} from './example.rule';\nimport {testRule} from '.';\n\ntestRule({\n    ruleName: exampleRule.name,\n    ruleOptions: [true],\n    fix: false,\n    accept: [\n        {\n            // this code should pass the rule\n            code: 'div { color: blue }',\n        },\n    ],\n    reject: [\n        {\n            // this code should fail the rule\n            code: 'div { color: blue; visibility: hidden; }',\n            message: exampleRule.messages.myMessageName('hidden'),\n        },\n    ],\n});\n```\n\n[See this file for example `Rule` tests.](https://github.com/electrovir/stylelint-rule-creator/blob/master/src/test/rules/visibility/visibility.test.ts)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felectrovir%2Fstylelint-rule-creator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felectrovir%2Fstylelint-rule-creator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felectrovir%2Fstylelint-rule-creator/lists"}