-
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?
Changes from 6 commits
a3bd485
3933f30
bcdb366
2b06eed
73fdbd2
b0eff2f
a23b89b
580e388
2259c48
c2d14a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "extends": "stylelint-config-wordpress" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,6 +166,15 @@ function set_environment_variables { | |
| ESLINT_IGNORE="$( upsearch .eslintignore )" | ||
| fi | ||
|
|
||
| if [ -z "$STYLELINT_CONFIG" ]; then | ||
| for SEARCHED_STYLELINT_CONFIG in .stylelintrc{,.yaml,.yml,.js,.json} stylelint.config.js; do | ||
| STYLELINT_CONFIG="$( upsearch $SEARCHED_STYLELINT_CONFIG )" | ||
| if [ ! -z "$STYLELINT_CONFIG" ]; then | ||
| break | ||
| fi | ||
| done | ||
| fi | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||
| # Load any environment variable overrides from config files | ||
| ENV_FILE=$( upsearch .ci-env.sh ) | ||
| if [ ! -z "$ENV_FILE" ]; then | ||
|
|
@@ -245,7 +254,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(:|$)' | cat - > "$TEMP_DIRECTORY/paths-scope-css" | ||
| cat "$TEMP_DIRECTORY/paths-scope" | grep -E '\.(xml|svg|xml.dist)(:|$)' | cat - > "$TEMP_DIRECTORY/paths-scope-xml" | ||
|
|
||
| # Gather the proper states of files to run through linting (this won't apply to phpunit) | ||
|
|
@@ -283,7 +292,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{,.yaml,.yml,.js,.json} stylelint.config.js phpcs.ruleset.xml ruleset.xml; do | ||
| if git ls-files "$linter_file" --error-unmatch > /dev/null 2>&1; then | ||
| if [ -L $linter_file ]; then | ||
| ln -fs $(git show :"$linter_file") "$LINTING_DIRECTORY/$linter_file" | ||
|
|
@@ -463,6 +472,18 @@ 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 stylelint" | ||
| if ! npm install -g stylelint 2>/dev/null; then | ||
| echo "Failed to install stylelint (try manually doing: sudo npm install -g stylelint), so skipping stylelint" | ||
| DEV_LIB_SKIP="$DEV_LIB_SKIP,stylelint" | ||
| elif ! -e node_modules/stylelint-formatter-compact; then | ||
| echo "The stylelint-formatter-compact node module is not installed, skipping stylelint." | ||
| DEV_LIB_SKIP="$DEV_LIB_SKIP,stylelint" | ||
| fi | ||
| fi | ||
|
|
||
| # YUI Compressor | ||
| if [ "$YUI_COMPRESSOR_CHECK" == 1 ] && command -v java >/dev/null 2>&1 && check_should_execute 'yuicompressor'; then | ||
| if [ ! -e "$YUI_COMPRESSOR_PATH" ]; then | ||
|
|
@@ -776,6 +797,35 @@ function lint_js_files { | |
| fi | ||
| } | ||
|
|
||
|
|
||
| function lint_css_files { | ||
| if [ ! -s "$TEMP_DIRECTORY/paths-scope-css" ]; then | ||
| return | ||
| fi | ||
|
|
||
| set -e | ||
|
|
||
| # Run ESLint. | ||
| if [ -n "$STYLELINT_CONFIG" ] && [ -e "$STYLELINT_CONFIG" ] && [ -e "$(npm bin)/stylelint" ] && check_should_execute 'stylelint'; then | ||
| ( | ||
| 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 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Swap the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ignore that ^^, the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't make a difference. Both Also, both |
||
| if [ "$CHECK_SCOPE" == 'patches' ]; then | ||
| cat "$TEMP_DIRECTORY/stylelint-report" | php "$DEV_LIB_PATH/diff-tools/filter-report-for-patch-ranges.php" "$TEMP_DIRECTORY/paths-scope-css" | cut -c$( expr ${#LINTING_DIRECTORY} + 2 )- | ||
| exit_code="${PIPESTATUS[1]}" | ||
| if [[ $exit_code != 0 ]]; then | ||
| return $exit_code | ||
| fi | ||
| elif [ -s "$TEMP_DIRECTORY/stylelint-report" ]; then | ||
| cat "$TEMP_DIRECTORY/stylelint-report" | cut -c$( expr ${#LINTING_DIRECTORY} + 2 )- | ||
| exit 1 | ||
| fi | ||
| fi | ||
| ) | ||
| fi | ||
| } | ||
|
|
||
| # @todo: This is wrong, as we should be doing `npm test` instead of calling `grunt qunit` directly. | ||
| function run_qunit { | ||
| if [ ! -s "$TEMP_DIRECTORY/paths-scope-js" ] || ! check_should_execute 'grunt'; then | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ echo "## Checking files, scope $CHECK_SCOPE:" | |
| cat "$TEMP_DIRECTORY/paths-scope" | ||
|
|
||
| check_execute_bit | ||
| lint_css_files | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As noted above, in a follow up PR we can add |
||
| lint_js_files | ||
| lint_php_files | ||
| lint_xml_files | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ fi | |
| echo | ||
|
|
||
| check_execute_bit | ||
| lint_css_files | ||
| lint_js_files | ||
| lint_php_files | ||
| lint_xml_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.
Also
*.yaml