stylelint-config-torchbox v3.0.0
stylelint-config-torchbox
Shareable stylelint config for CSS and SCSS, following Torchbox’s code style.
Usage
Install stylelint, and the config:
npm install --save-dev stylelint@13 stylelint-config-torchbox@1.0.0Then configure stylelint to use this config. As a stylelint.config.js in the root of your project:
module.exports = {
// See https://github.com/torchbox/stylelint-config-torchbox for rules.
extends: 'stylelint-config-torchbox',
};Tips
Linting setup for ongoing projects
Review our CHANGELOG for guidance on how to upgrade a project’s linting to a specific version.
More generally, when retrofitting stricter linting onto an existing project, consider a gradual approach to linting strictness, so you can start using linting without having to change significant portions of the project’s code. Here is an example, disabling commonly hard-to-retrofit rules:
// Rules which we ideally would want to enforce but are reporting too many issues currently.
const legacyRules = {
'max-nesting-depth': null,
'selector-max-specificity': null,
};
module.exports = {
// See https://github.com/torchbox/stylelint-config-torchbox for rules.
extends: 'stylelint-config-torchbox',
rules: {
...legacyRules,
},
};Common CLI flags
We recommend the following run script to add to your package.json:
"lint:css": "stylelint --report-needless-disables 'src/sass' 'src/vue'"- Use
--report-needless-disablesflag to ensure you do not use morestylelint-disablecomments than needed. - Target specific folders so Stylelint doesn’t attempt to lint e.g. JS or HTML files.
.stylelintignore
Stylelint supports ignore patterns in a .stylelintignore file, however we tend not to use this since we lint all files within a given folder.
Prettier
This config is Prettier-compatible, there isn’t anything extra needed.
Tailwind
This config should work with Tailwind with no adjustments needed. Please submit an issue if that’s not the case.
pre-commit
Here is a sample setup with our recommended configuration for the pre-commit pre-commit hook framework:
default_language_version:
node: system
repos:
- repo: https://github.com/thibaudcolas/pre-commit-stylelint
rev: v13.13.1
hooks:
- id: stylelint
files: \.(scss|vue)$
additional_dependencies:
- stylelint@13.13.1
- stylelint-config-torchbox@1.0.0Vue
Stylelint supports Vue, and our configuration is usable in .vue single-file components with no changes. Do make sure linting is configured to check .vue files:
- Wherever
stylelintis manually invoked, make sure to point it both at stylesheets, and Vue components:stylelint --report-needless-disables './src/sass' './src/vue_components'. - With
stylelint-webpack-plugin, useextensions: ['scss', 'vue'],. - With
pre-commit, usefiles: \.(scss|vue)$.
Related tools
To get the most out of this config, it is assumed that projects have the following tools set up:
- Prettier for automated formatting of stylesheets.
- Browserslist and autoprefixer.
What’s included
See
config.jsfor the config definition. This package includes configuration from:
Rules
For the full list of enabled, disabled, and unused rules, view src/rules.md.
Custom rules
color-named:neverdeclaration-block-no-shorthand-property-overridesdeclaration-no-importantselector-max-id:0selector-max-type:2, ignore: child, compounded, next-siblingselector-class-pattern:, resolveNestedSelectors: truemax-nesting-depth:4selector-max-specificity:0,4,0value-no-vendor-prefixproperty-no-vendor-prefixselector-no-vendor-prefixmedia-feature-name-no-vendor-prefixat-rule-no-vendor-prefixdeclaration-property-value-disallowed-list:text-align: justifyscss/at-rule-no-unknown:true, ignoreAtRules: tailwind, apply, variants, responsive, screen, layerscss/declaration-nested-properties:neverscss/selector-no-redundant-nesting-selectorscss/percent-placeholder-pattern:^do-not-use-placeholders$scss/dollar-variable-no-missing-interpolationscss/at-mixin-argumentless-call-parentheses:alwaysscss/at-mixin-pattern:order/order:dollar-variables, custom-properties, type: at-rule, hasBlock: false, declarationsscale-unlimited/declaration-strict-value:color, fill, stroke, /-color/, ignoreKeywords: currentColor, inherit, transparent, initial, none, unset, Canvas, CanvasText, LinkText, VisitedText, ActiveText, ButtonFace, ButtonText, ButtonBorder, Field, FieldText, Highlight, HighlightText, SelectedItem, SelectedItemText, Mark, MarkText, GrayText, AccentColor, AccentColorText
Inherited rules
block-no-emptycolor-hex-length:shortcolor-no-invalid-hexcomment-empty-line-before:always, except: first-nested, ignore: stylelint-commandscomment-whitespace-inside:alwayscustom-property-empty-line-before:always, except: after-custom-property, first-nested, ignore: after-comment, inside-single-line-blockcustom-property-no-missing-var-functiondeclaration-block-no-duplicate-custom-propertiesdeclaration-block-no-duplicate-properties:true, ignore: consecutive-duplicates-with-different-syntaxesdeclaration-block-single-line-max-declarations:1font-family-name-quotes:always-where-recommendedfont-family-no-duplicate-namesfont-family-no-missing-generic-family-keywordfunction-calc-no-unspaced-operatorfunction-linear-gradient-no-nonstandard-directionfunction-name-case:lowerfunction-url-quotes:alwayshue-degree-notation:angleimport-notation:stringkeyframe-block-no-duplicate-selectorskeyframe-declaration-no-importantkeyframe-selector-notation:percentage-unless-within-keyword-only-blocklength-zero-no-unit:true, ignore: custom-propertiesmedia-feature-name-no-unknownnamed-grid-areas-no-invalidno-duplicate-at-import-rulesno-duplicate-selectorsno-empty-sourceno-invalid-double-slash-commentsno-invalid-position-at-import-rule:true, ignoreAtRules: use, forwardno-irregular-whitespacenumber-max-precision:4property-no-unknownrule-empty-line-before:always-multi-line, except: first-nested, ignore: after-commentscss/at-else-closing-brace-newline-after:always-last-in-chainscss/at-else-closing-brace-space-after:always-intermediatescss/at-else-empty-line-before:neverscss/at-else-if-parentheses-space-before:alwaysscss/at-function-parentheses-space-before:neverscss/at-if-closing-brace-newline-after:always-last-in-chainscss/at-if-closing-brace-space-after:always-intermediatescss/at-if-no-nullscss/at-import-no-partial-leading-underscorescss/at-import-partial-extension:neverscss/at-mixin-parentheses-space-before:neverscss/at-rule-conditional-no-parenthesesscss/comment-no-emptyscss/declaration-nested-properties-no-divided-groupsscss/dollar-variable-colon-space-after:alwaysscss/dollar-variable-colon-space-before:neverscss/double-slash-comment-whitespace-inside:alwaysscss/function-quote-no-quoted-strings-insidescss/function-unquote-no-unquoted-strings-insidescss/no-duplicate-mixinsscss/operator-no-newline-afterscss/operator-no-newline-beforescss/operator-no-unspacedselector-anb-no-unmatchableselector-attribute-quotes:alwaysselector-pseudo-class-no-unknownselector-pseudo-element-colon-notation:doubleselector-pseudo-element-no-unknownselector-type-case:lowerselector-type-no-unknown:true, ignore: custom-elementsstring-no-newlineunit-no-unknownvalue-keyword-case:lower
Contributing
See the contribution guidelines for guidance and setup instructions.