Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Add stylelint integration #239

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

Add stylelint integration #239

wants to merge 10 commits into from

Conversation

westonruter
Copy link
Contributor

Fixes #47

Copy link

@ntwb ntwb left a 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
@@ -463,6 +470,15 @@ function install_tools {
fi
fi

# Install stylelint
if [ -n "$STYLELINT_CONFIG" ] && [ -e "$STYLELINT_CONFIG" ] && [ ! -e "$(npm bin)/stylelint" ] && check_should_execute 'stylelint'; then
echo "Installing ESLint"
Copy link

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
Copy link

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

check-diff.sh Outdated
if [ -z "$STYLELINT_CONFIG" ]; then
STYLELINT_CONFIG="$( upsearch stylelint.config.js )"
fi

Copy link

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 .stylelintrc file (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
@@ -245,7 +252,7 @@ function set_environment_variables {

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"
Copy link

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
@@ -283,7 +290,7 @@ function set_environment_variables {
done

# 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
Copy link

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
Copy link

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

Copy link
Contributor Author

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

@@ -40,6 +40,7 @@ echo "## Checking files, scope $CHECK_SCOPE:"
cat "$TEMP_DIRECTORY/paths-scope"

check_execute_bit
lint_css_files
Copy link

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
ln -s dev-lib/.editorconfig . && git add .editorconfig
cp dev-lib/.jshintignore . && git add .jshintignore # don't use symlink for this
```

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:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

them, not then

@westonruter westonruter changed the title [WIP] Add stylelint integration Add stylelint integration May 17, 2017
@westonruter
Copy link
Contributor Author

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
Copy link
Contributor Author

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?

Copy link

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

Copy link

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

Copy link
Contributor Author

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
@@ -10,7 +10,7 @@ insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[{package.json,*.yml}]
[{*.json,*.yml,.stylelintrc,.jshintrc,.eslintrc,.jscsrc}]
Copy link

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
Copy link

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
@@ -10,7 +10,7 @@ insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[{package.json,*.yml}]
[{*.json,*.yml,*.yaml,.stylelintrc,.jshintrc,.eslintrc,.jscsrc}]
Copy link

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

See https://core.trac.wordpress.org/ticket/40946

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants