-
Notifications
You must be signed in to change notification settings - Fork 56
Add stylelint integration #239
base: master
Are you sure you want to change the base?
Conversation
ntwb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome @westonruter, I've added numerous inline comments 👍
check-diff.sh
Outdated
|
|
||
| # Install stylelint | ||
| if [ -n "$STYLELINT_CONFIG" ] && [ -e "$STYLELINT_CONFIG" ] && [ ! -e "$(npm bin)/stylelint" ] && check_should_execute 'stylelint'; then | ||
| echo "Installing ESLint" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be echo "Installing stylelint"
check-diff.sh
Outdated
| # Install stylelint | ||
| if [ -n "$STYLELINT_CONFIG" ] && [ -e "$STYLELINT_CONFIG" ] && [ ! -e "$(npm bin)/stylelint" ] && check_should_execute 'stylelint'; then | ||
| echo "Installing ESLint" | ||
| if ! npm install -g eslint 2>/dev/null; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be if ! npm install -g stylelint 2>/dev/null; then
| if [ -z "$STYLELINT_CONFIG" ]; then | ||
| STYLELINT_CONFIG="$( upsearch stylelint.config.js )" | ||
| fi | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stylelint supports a few more config files, not sure if you want to include all possible combinations here
Via https://stylelint.io/user-guide/configuration/
The.stylelintrcfile (without extension) can be in JSON or YAML format. Alternately, you can add a filename extension to designate JSON, YAML, or JS format:.stylelintrc.json,.stylelintrc.yaml,.stylelintrc.yml,.stylelintrc.js. You may want to use an extension so that your text editor can better interpret the file, and help with syntax checking and highlighting.
check-diff.sh
Outdated
| cat "$TEMP_DIRECTORY/paths-scope" | grep -E '\.php(:|$)' | cat - > "$TEMP_DIRECTORY/paths-scope-php" | ||
| cat "$TEMP_DIRECTORY/paths-scope" | grep -E '\.jsx?(:|$)' | cat - > "$TEMP_DIRECTORY/paths-scope-js" | ||
| cat "$TEMP_DIRECTORY/paths-scope" | grep -E '\.(css|scss)(:|$)' | cat - > "$TEMP_DIRECTORY/paths-scope-scss" | ||
| cat "$TEMP_DIRECTORY/paths-scope" | grep -E '\.(css|scss)(:|$)' | cat - > "$TEMP_DIRECTORY/paths-scope-css" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's drop scss from the above and only go with css initially.
The stylelint-config-wordpress configuration includes two stylelint shared configs, one for CSS and one for SCSS, so let's get CSS up and running and follow up with with SCSS in another PR
check-diff.sh
Outdated
|
|
||
| # Make sure linter configs get copied linting directory since upsearch is relative. | ||
| for linter_file in .jshintrc .jshintignore .jscsrc .jscs.json .eslintignore .eslintrc phpcs.ruleset.xml ruleset.xml; do | ||
| for linter_file in .jshintrc .jshintignore .jscsrc .jscs.json .eslintignore .eslintrc .stylelintrc stylelint.config.js phpcs.ruleset.xml ruleset.xml; do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See also above comment on adding all possibilities of valid stylelint configuration file names.
check-diff.sh
Outdated
| echo "## stylelint" | ||
| cd "$LINTING_DIRECTORY" | ||
| # TODO: --format=compact is not right. | ||
| if ! cat "$TEMP_DIRECTORY/paths-scope-css" | remove_diff_range | xargs "$(npm bin)/stylelint" --format=compact --config="$STYLELINT_CONFIG" > "$TEMP_DIRECTORY/stylelint-report"; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than --format=compact, it should be --custom-formatter stylelint-formatter-compact
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that it actually needs to be --custom-formatter node_modules/stylelint-formatter-compact
| cat "$TEMP_DIRECTORY/paths-scope" | ||
|
|
||
| check_execute_bit | ||
| lint_css_files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted above, in a follow up PR we can add lint_scss_files
readme.md
Outdated
| ``` | ||
|
|
||
| For ESLint, you'll also likely want to make `eslint` as a dev dependency for your NPM package: | ||
| For ESLint and stylelint, you'll also likely want to make then dev dependencies for your NPM package: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
them, not then
|
Example working integration: xwp/wp-core-media-widgets#183 |
| ( | ||
| echo "## stylelint" | ||
| cd "$LINTING_DIRECTORY" | ||
| if ! cat "$TEMP_DIRECTORY/paths-scope-css" | remove_diff_range | xargs "$(npm bin)/stylelint" --custom-formatter=node_modules/stylelint-formatter-compact --config="$STYLELINT_CONFIG" > "$TEMP_DIRECTORY/stylelint-report"; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the node_modules/stylelint-formatter-compact part. What if stylelint-formatter-compact is installed globally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swap the = for a space , i.e: --custom-formatter node_modules/stylelint-formatter-compact
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore that ^^, the = does not matter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't make a difference. Both --custom-formatter node_modules/stylelint-formatter-compact and --custom-formatter=node_modules/stylelint-formatter-compact have the same result.
Also, both --custom-formatter stylelint-formatter-compact and --custom-formatter=stylelint-formatter-compact fail with: “Error: Cannot find module”.
.editorconfig
Outdated
| indent_style = tab | ||
|
|
||
| [{package.json,*.yml}] | ||
| [{*.json,*.yml,.stylelintrc,.jshintrc,.eslintrc,.jscsrc}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also *.yaml
| ( | ||
| echo "## stylelint" | ||
| cd "$LINTING_DIRECTORY" | ||
| if ! cat "$TEMP_DIRECTORY/paths-scope-css" | remove_diff_range | xargs "$(npm bin)/stylelint" --custom-formatter=node_modules/stylelint-formatter-compact --config="$STYLELINT_CONFIG" > "$TEMP_DIRECTORY/stylelint-report"; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swap the = for a space , i.e: --custom-formatter node_modules/stylelint-formatter-compact
.editorconfig
Outdated
| indent_style = tab | ||
|
|
||
| [{package.json,*.yml}] | ||
| [{*.json,*.yml,*.yaml,.stylelintrc,.jshintrc,.eslintrc,.jscsrc}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is no longer needed, all .json files should now use tabs for indentation
…onfigs" This partially reverts commit b0eff2f.
Fixes #47