Skip to content

stylelint-stylus

Stylelint plugin for Stylus.

This plugin is still in an experimental state

NPM licenseNPM versionNPM downloadsBuild Status


๐Ÿ“› Introduction โ€‹

Stylelint plugin for Stylus.

This plugin allows us to check the Stylus with Stylelint.

  • Finds the many wrong use of selector, declaration, at-rule and more using the rules of Stylelint.
  • Finds the violations in coding style for Stylus.
  • Use the fix option to automatically fixes the many stylistic violations.

Stylelint editor integrations are useful to check your code in real-time.

You can check on the Online DEMO.

๐Ÿ’ฟ Installation โ€‹

Via npm:

bash
npm install --save-dev stylelint stylelint-stylus

๐Ÿ“– Usage โ€‹

stylelint-stylus is a plugin for Stylelint, so it is for use with Stylelint.
If you are not using Stylelint, start by using Stylelint.

Configuration โ€‹

Use .stylelintrc.* or stylelint.config.js file to configure rules. See also: https://stylelint.io/user-guide/configure.

Example stylelint.config.js:

js
module.exports = {
  extends: [
    // add more generic rulesets here, such as:
    // "stylelint-config-standard",
    "stylelint-stylus/standard",
  ],
  rules: {
    // override/add rules settings here, such as:
    // "stylus/declaration-colon": "never"
  },
};

If you want to set all the rules yourself, set as follows.

js
module.exports = {
  plugins: [
    // add this plugin here:
    "stylelint-stylus",
  ],
  // makes the stylus files parseable.
  overrides: [
    {
      files: ["*.stylus", "*.styl", "**/*.stylus", "**/*.styl"],
      customSyntax: "postcss-styl",
    },
  ],
  rules: {
    // add rules settings here, such as:
    "stylus/declaration-colon": "never",
    "stylus/pythonic": "always",
    "stylus/selector-list-comma": "never",
    "stylus/semicolon": "never",
    "stylus/single-line-comment": "always",
  },
};

๐Ÿ’ป Editor integrations โ€‹

Visual Studio Code โ€‹

Use the stylelint.vscode-stylelint extension that Stylelint provides officially.

You have to configure the stylelint.validate option of the extension to check .stylus files, because the extension does not check the *.stylus file by default.

Example .vscode/settings.json:

jsonc
{
  "stylelint.validate": [
      ...,
      // โ†“ Add "stylus" language.
      "stylus"
  ]
}

Custom Syntax โ€‹

If you are using stylelint v13, you need to do the following:

Set custom syntax for parsing Stylus. With the following setting, .styl and <style lang="stylus"> are parsed by postcss-styl.

  • via CLI

    bash
    stylelint ... --custom-syntax stylelint-stylus/custom-syntax
  • with VSCode extension

    json
    {
      "stylelint.customSyntax": "stylelint-stylus/custom-syntax",
      "stylelint.validate": [
        ...,
        // โ†“ Add "stylus" language.
        "stylus"
      ]
    }

โคด๏ธ RuleSets โ€‹

This plugin provides some rulesets. It can be used by specifying it in the extends of the Stylelint configuration.

  • "stylelint-stylus/recommended" ... Turns Off rules that cannot be used with the Stylus within stylelint (WIP). And turns On rules that possible errors rules within stylelint-stylus.
  • "stylelint-stylus/standard" ... Above, plus rules to improve code readability.

โœ… Rules โ€‹

You can use the rules built into Stylelint and the rules provided by this plugin.

The --fix option on the command line automatically fixes problems reported by rules which have a wrench ๐Ÿ”ง below.

Possible Errors Rules โ€‹

These rules relate to possible syntax or logic errors in Stylus.

Rule IDDescriptionRuleSet
stylus/at-rule-no-unknowndisallow unknown at-rules./recommended
stylus/property-no-unknowndisallow unknown properties./recommended
stylus/selector-type-no-unknowndisallow unknown type selectors./recommended
stylus/single-line-comment-no-emptydisallow empty single-line comments./recommended

Standard Rules โ€‹

These rules relate to style guidelines.

Rule IDDescriptionRuleSet
๐Ÿ”งstylus/at-extend-styleenforces @extend style./standard
๐Ÿ”งstylus/at-rule-empty-line-beforerequire or disallow an empty line before at-rules./standard
๐Ÿ”งstylus/at-rule-name-space-afterrequire a single space after at-rule names./standard
๐Ÿ”งstylus/block-closing-brace-empty-line-beforerequire or disallow an empty line before the closing brace of blocks./standard
๐Ÿ”งstylus/block-closing-brace-newline-afterrequire a newline or disallow whitespace after the closing brace of blocks./standard
๐Ÿ”งstylus/block-closing-brace-newline-beforerequire a newline or disallow whitespace before the closing brace of blocks./standard
stylus/block-closing-brace-space-afterrequire a single space or disallow whitespace after the closing brace of blocks.
๐Ÿ”งstylus/block-closing-brace-space-beforerequire a single space or disallow whitespace before the closing brace of blocks./standard
๐Ÿ”งstylus/block-opening-brace-newline-afterrequire a newline after the opening brace of blocks./standard
๐Ÿ”งstylus/block-opening-brace-space-afterrequire a single space or disallow whitespace after the opening brace of blocks./standard
๐Ÿ”งstylus/block-opening-brace-space-beforerequire a single space or disallow whitespace before the opening brace of blocks./standard
๐Ÿ”งstylus/color-hex-caseenforce lowercase or uppercase for hex colors./standard
๐Ÿ”งstylus/declaration-colonrequire or disallow declaration colons./standard
๐Ÿ”งstylus/hash-object-property-commarequire or disallow commas in hash object properties./standard
๐Ÿ”งstylus/indentationenforces indentation./standard
๐Ÿ”งstylus/media-feature-colonrequire or disallow media feature colons./standard
๐Ÿ”งstylus/no-at-requiredisallow @require, use @import instead./standard
๐Ÿ”งstylus/no-eol-whitespacedisallow end-of-line whitespace./standard
๐Ÿ”งstylus/number-leading-zerorequire or disallow a leading zero for fractional numbers less than 1./standard
๐Ÿ”งstylus/number-no-trailing-zerosdisallow trailing zeros in numbers./standard
๐Ÿ”งstylus/pythonicenforces pythonic or brace style./standard
๐Ÿ”งstylus/selector-list-comma-newline-afterrequire a newline or disallow whitespace after the commas of selector lists./standard
๐Ÿ”งstylus/selector-list-comma-newline-beforerequire a newline or disallow whitespace before the commas of selector lists.
๐Ÿ”งstylus/selector-list-comma-space-afterrequire a single space or disallow whitespace after the commas of selector lists.
๐Ÿ”งstylus/selector-list-comma-space-beforerequire a single space or disallow whitespace before the commas of selector lists./standard
๐Ÿ”งstylus/selector-list-commarequire or disallow selector list comma./standard
๐Ÿ”งstylus/selector-pseudo-class-caseenforce lowercase or uppercase for pseudo-class selectors./standard
๐Ÿ”งstylus/semicolonrequire or disallow semicolon./standard
๐Ÿ”งstylus/single-line-comment-double-slash-space-afterrequire or disallow whitespace after the double-slash of single-line comments./standard
๐Ÿ”งstylus/single-line-commentenforces comment style where single-line comments are allowed./standard

License โ€‹

See the LICENSE file for license rights and limitations (MIT).