Skip to content

Commit

Permalink
fix: actually run stylelint
Browse files Browse the repository at this point in the history
  • Loading branch information
kdmccormick committed Oct 29, 2024
1 parent 50f8979 commit 7aeb0da
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 56 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/quality-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,19 @@ jobs:
PIP_SRC: ${{ runner.temp }}
run: |
make test-requirements
- name: Install npm
env:
PIP_SRC: ${{ runner.temp }}
run: npm ci

NODE_ENV: development
run: npm ci

- name: Install python packages
env:
PIP_SRC: ${{ runner.temp }}
run: |
pip install -e .
- name: Run Quality Tests
env:
PIP_SRC: ${{ runner.temp }}
Expand All @@ -83,7 +84,7 @@ jobs:
make xsslint
make pii_check
make check_keywords
- name: Save Job Artifacts
if: always()
uses: actions/upload-artifact@v4
Expand Down
63 changes: 12 additions & 51 deletions scripts/quality_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,42 +117,6 @@ def _get_count_from_last_line(filename, file_type):
return None


def _get_stylelint_violations():
"""
Returns the number of Stylelint violations.
"""
REPO_ROOT = repo_root()
REPORT_DIR = REPO_ROOT / 'reports'
stylelint_report_dir = (REPORT_DIR / "stylelint")
stylelint_report = stylelint_report_dir / "stylelint.report"
_prepare_report_dir(stylelint_report_dir)

command = [
'node', 'node_modules/stylelint',
'*scss_files',
'--custom-formatter', 'stylelint-formatter-pretty/index.js'
]

with open(stylelint_report, 'w') as report_file:
subprocess.run(
command,
check=True,
stdout=report_file,
stderr=subprocess.STDOUT,
text=True
)

try:
return int(_get_count_from_last_line(stylelint_report, "stylelint"))
except TypeError:
fail_quality(
'stylelint',
"FAILURE: Number of stylelint violations could not be found in {stylelint_report}".format(
stylelint_report=stylelint_report
)
)


def run_eslint():
"""
Runs eslint on static asset directories.
Expand Down Expand Up @@ -211,23 +175,20 @@ def run_eslint():
def run_stylelint():
"""
Runs stylelint on Sass files.
If limit option is passed, fails build if more violations than the limit are found.
"""

violations_limit = 0
num_violations = _get_stylelint_violations()
# Fail if number of violations is greater than the limit
if num_violations > violations_limit:
fail_quality(
'stylelint',
"FAILURE: Stylelint failed with too many violations: ({count}).\nThe limit is {violations_limit}.".format(
count=num_violations,
violations_limit=violations_limit,
)
command = ['stylelint', '**/*.scss', '--custom-formatter', 'stylelint-formatter-pretty/index.js']
import shlex
print(shlex.join(command))
try:
subprocess.run(
command,
check=True,
text=True,
)
else:
print("successfully run stylelint with violations")
print(num_violations)
except subprocess.CalledProcessError:
print("stylelint failed")
sys.exit(1)
print("stylelint passed")


def _extract_missing_pii_annotations(filename):
Expand Down

0 comments on commit 7aeb0da

Please sign in to comment.