Skip to content

Add stylelint as an alternate CSS linter. #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mparker17
Copy link
Owner

@mparker17 mparker17 commented Dec 20, 2017

Inspired by Clean CSS with Stylelint by @dbuytaert.

Note the linter added in this pull request assumes some changes from the configuration presented in the post above:

In order for stylelint to pick up its configuration automatically, I had to:

  1. Rename the configuration file from stylelint.js to .stylelintrc,
  2. Remove the 'use strict' statement at the beginning of the file, and,
  3. Remove the module.exports = assignment before the JSON settings array.

In order for stylelint to work with the configuration file, but not require the --config-basedir argument, I had to:

  1. Install stylelint-config-standard and stylelint-no-browser-hacks locally, i.e.:

     npm install stylelint-config-standard stylelint-no-browser-hacks
    

See the d6bf406 commit message for a bit more information.

Note this assumes a few things:

1. Your stylelint configuration can be auto-detected. That is to say, as
   of stylelint version 8.4.0:
    * your configuration is located in a stylelint property in
      `package.json`, or,
    * your configuration is located in a `.stylelintrc` file (with or
      without one of the following filename extensions: .json, .yaml,
      .yml, and .js) in the current directory or one of its ancestors,
      or,
    * your configuration is located in a `stylelint.config.js` file
      exporting a JS object, located in the current directory or one of
      its ancestors.

   I found that, if my config was named `.stylelintrc`, it could not
   contain a 'use strict' statement at the beginning of the file nor the
   assignment 'module.exports = ' before the JSON array of settings.
   This may have been unique to my environment.

2. Your stylelint configuration doesn't contain any global dependencies.
   That is to say, stylelint has been installed with `npm install -g
   stylelint`, but packages such as stylelint-config-standard and
   stylelint-no-browser-hacks has been installed locally with `npm
   install stylelint-config-standard stylelint-no-browser-hacks`.

   If you do have global dependencies, you will need to add a
   `--config-basedir` argument to the `stylelint "$file"` line in
   `pre-commit/2-css-style-stylelint.sh`, e.g.:

            stylelint --config-basedir /usr/local/lib/node_modules/ "$file"
- .theme is new in D8
- Drupal sniffs can run on js, css, and yml files
- .theme is new in D8
- DrupalPractice sniffs can run on yml files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant