Code Monkey home page Code Monkey logo

stylelint-config-torchbox's Introduction

Shareable stylelint config for CSS and SCSS, following Torchbox’s code style.

Usage

Install stylelint, and the config:

npm install --save-dev stylelint stylelint-config-torchbox

Then 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-disables flag to ensure you do not use more stylelint-disable comments 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: v15.10.3
    hooks:
      - id: stylelint
        files: \.(scss|vue)$
        additional_dependencies:
          - [email protected]
          - [email protected]

Vue

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 stylelint is 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, use extensions: ['scss', 'vue'],.
  • With pre-commit, use files: \.(scss|vue)$.

Related tools

To get the most out of this config, it is assumed that projects have the following tools set up:

What’s included

See config.js for 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

Inherited rules

Contributing

See the contribution guidelines for guidance and setup instructions.

stylelint-config-torchbox's People

Contributors

renovate-bot avatar renovate[bot] avatar stevedya avatar thibaudcolas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stylelint-config-torchbox's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Migration from sass-lint

TODO

Major differences / additions to review

We’ll add all of these for now, can revise if needed

Migration progress

With old sass-lint config in red, new stylelint config in green:

# Won’t be enforced anymore.
-  bem-depth:
-    - 1
-    - max-depth: 2
# Completely disallow @extend
-  extends-before-mixins: 2
-  extends-before-declarations: 2
-  placeholder-in-extend: 2
+ 'scss/percent-placeholder-pattern': '^do-not-use-placeholders$',
# stylelint-config-prettier
-  empty-line-between-blocks:
-    - 2
-    - include: true
-    - allow-single-line-rulesets: false
# Done with stylelint-order
-  mixins-before-declarations:
-    - 2
-    - exclude:
-        - media-query
+ 'order/order': [
+     'dollar-variables',
+     'custom-properties',
+     // @-rules that have no nesting.
+     { type: 'at-rule', hasBlock: false },
+     'declarations',
+     'rules',
+     // @-rules that have nested elements, e.g. media queries
+     { type: 'at-rule', hasBlock: true },
+ ],
# Not enforced by stylelint.
-  no-warn: 0
-  no-debug: 0
# stylelint-config-prettier
-  indentation: 0
# Not enforced by stylelint.
-  variable-for-property:
-    - 0
# Not enforced by stylelint.
-  no-css-comments: 0
# TODO with a regex for selector-class-pattern.
  class-name-format:
    - 1
    - convention: hyphenatedbem
# Not enforced by styellint.
-   force-pseudo-nesting: 0
# Now enforced
-  nesting-depth: 0
+ 'max-nesting-depth': 4,
# Not enforced by styellint.
-  force-attribute-nesting: 0
- # This seems hard / impossible to enforce. Removing.
-  force-element-nesting: 1
# Not enforced
-  no-qualifying-elements: 0
# Done with number-leading-zero
-  leading-zero:
-    - 1
-    - include: true
+ 'number-leading-zero': 'always',
# Enforced with multiple rules
-  no-vendor-prefixes:
-    - 1
+ 'value-no-vendor-prefix': true,
+ 'property-no-vendor-prefix': true,
+ 'selector-no-vendor-prefix': true,
+ 'media-feature-name-no-vendor-prefix': true,
+ 'at-rule-no-vendor-prefix': true,
# TODO
  mixin-name-format:
    - 1
    - convention: hyphenatedlowercase
# Now enforced.
-  no-color-keywords: 0
+ 'color-named': 'never',
# Not enforced by stylelint.
-  no-color-literals: 0
# Not enforced by stylelint.
-  property-sort-order: 0
# Enforced with stylelint-scss
-  empty-args:
-    - 1
-    - include: true
+ 'scss/at-mixin-argumentless-call-parentheses': 'always',

Base sass-lint config

  bem-depth:
    - 1
    - max-depth: 2
  extends-before-mixins: 2
  extends-before-declarations: 2
  placeholder-in-extend: 2
  empty-line-between-blocks:
    - 2
    - include: true
    - allow-single-line-rulesets: false
  mixins-before-declarations:
    - 2
    - exclude:
        - media-query
  no-warn: 0
  no-debug: 0
  indentation: 0
  variable-for-property:
    - 0
  no-css-comments: 0
  class-name-format:
    - 1
    - convention: hyphenatedbem
  force-pseudo-nesting: 0
  nesting-depth: 0
  force-attribute-nesting: 0
  force-element-nesting: 1
  no-qualifying-elements: 0
  leading-zero:
    - 1
    - include: true
  no-vendor-prefixes:
    - 1
  mixin-name-format:
    - 1
    - convention: hyphenatedlowercase
  no-color-keywords: 0
  no-color-literals: 0
  property-sort-order: 0
  empty-args:
    - 1
    - include: true

CssSyntaxError on Vue files after stylelint v14 upgrade

After upgrading Wagtail-Kit's stylelint to version 14.X and stylelint-config-torchbox to version 2.0.3, Vue files started to spit out a CssSyntaxError. Running npm run lint:css (stylelint --report-needless-disables './wagtailkit_repo_name/static_src/sass' './wagtailkit_repo_name/static_src/javascript/vue_components'), we get:

wagtailkit_repo_name/static_src/javascript/vue_components/Hello.vue
 3:28  ✖  Unknown word  CssSyntaxError

1 problem (1 error, 0 warnings)

The problematic line contains the following:

    <p class="greeting">{{ greeting }} world</p>

It seems like other people have run into this before (stylelint/stylelint#5634 and stylelint/stylelint#3633) and their issues seemed to be related to stylelint's Vue configuration.

In fact, if we add a custom syntax rule for Vue files at .stylelintrc:

module.exports = {
    // See https://github.com/torchbox/stylelint-config-torchbox for rules.
    extends: 'stylelint-config-torchbox',
    overrides: [
        {
             // Ensure Vue files aren't treated solely as html or scss
            files: ["*.vue"],
            customSyntax: "postcss-html"
        },
    ],
};

and install/add postcss-html to our dev-dependencies, the error goes away.

Although the error started appearing after the v14 update, it is still present at stylelint v15 and the latest stylelint-config-torchbox versions.

Plugins or rules to consider for inclusion

We didn’t have time to look at additional plugins we could benefit from – here is the list I wanted us to consider:

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
.github/workflows/codeql-analysis.yml
  • actions/checkout v3
  • github/codeql-action v2
  • github/codeql-action v2
npm
package.json
  • stylelint-a11y ^1.2.3
  • stylelint-config-prettier ^8.0.2
  • stylelint-config-standard ^20.0.0
  • stylelint-declaration-strict-value ^1.6.1
  • stylelint-order ^4.1.0
  • stylelint-scss ^3.18.0
  • eslint 8.20.0
  • jest 28.1.3
  • prettier 2.7.1
  • stylelint 13.7.2
  • stylelint-find-new-rules 3.0.4
  • stylelint ^13.0.0
nvm
.nvmrc
  • node 16

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.