Skip to content

Commit

Permalink
Pre commit linting (#2955)
Browse files Browse the repository at this point in the history
* config: Add pre-commit rules and linting configuration

- Add more extensive pre-commit rules for linting and formatting
- Move CSS/SCSS linting to use stylelint
- Update prettier to apply to all file types (including Django templates)
- Add actionlint for ensuring correctness of GH Actions workflows
- Remove custom issue/PR templates in favor of org-global templates from mitodl/.github

(cherry picked from commit 917801fcd422e0afd471c4fac12b364fa59e2df5)

* fix,style: Apply automated fixes from pre-commit hooks

(cherry picked from commit 7babc00de756a9c3d2a8145cf7461872d52bbf52)

* fix: Resolve broken tests

(cherry picked from commit ed7363bb4a41043ca9c58de1f7667a16d08f68ea)

* style: Apply pre-commit changes

* config: Fix JS lint configs for pre-commit usage

* fix,style: Address lint failures for JS and SCSS

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix: Pass explicit exception to suppress

* fix: Resolve webpack build failure

- Fix invalid CSS rules
- Fix config path for Prettier in GH Actions
- Temporarily ignore unparseable files for Prettier

* version: Update Poetry locks

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
blarghmatey and pre-commit-ci[bot] authored May 6, 2024
1 parent 22472e4 commit dfcc797
Show file tree
Hide file tree
Showing 461 changed files with 17,321 additions and 14,536 deletions.
7 changes: 4 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"extends": "eslint-config-mitodl",
"extends": ["eslint-config-mitodl", "prettier"],
"settings": {
"react": {
"pragma": "React",
"version": "detect",
"flowVersion": "0.2.3"
}
},
rules: {
"rules": {
"no-unused-vars": 0,
// module importing pattern have huge impact over performance, especially when it comes to lodash
// the below rule will restrict developers to do lodash global imports
Expand All @@ -21,5 +21,6 @@
]
}
]
}
},
"ignorePatterns": ["scripts/repl.js", "flow-typed/npm/moment_v2.x.x.js"]
}
52 changes: 23 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
--health-retries 5
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres # pragma: allowlist secret
POSTGRES_PASSWORD: postgres # pragma: allowlist secret
POSTGRES_DB: postgres
ports:
- 5432:5432
Expand Down Expand Up @@ -48,25 +48,19 @@ jobs:
- name: Install poetry
uses: snok/install-poetry@v1
with:
version: 1.5.1
version: 1.8.2
virtualenvs-create: true
virtualenvs-in-project: true

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9.14"
cache: 'poetry'
python-version: "3.9.15"
cache: "poetry"

- name: Install dependencies
run: poetry install --no-interaction

- name: Lint (Ruff)
run: poetry run ruff check .

- name: Code Formatting (Ruff)
run: poetry run ruff format --check .

# Configurations required for elasticsearch.
- name: Configure sysctl limits
run: |
Expand All @@ -85,49 +79,49 @@ jobs:
celery -A mitxpro worker -B -l INFO &
sleep 10
env:
CELERY_TASK_ALWAYS_EAGER: 'True'
CELERY_TASK_ALWAYS_EAGER: "True"
CELERY_BROKER_URL: redis://localhost:6379/4
CELERY_RESULT_BACKEND: redis://localhost:6379/4
SECRET_KEY: local_unsafe_key # pragma: allowlist secret
SECRET_KEY: local_unsafe_key # pragma: allowlist secret
MITOL_HUBSPOT_API_PRIVATE_TOKEN: test-token
MITXPRO_BASE_URL: http://localhost:8053
MAILGUN_SENDER_DOMAIN: other.fake.site
MAILGUN_KEY: fake_mailgun_key
MITXPRO_ADMIN_EMAIL: example@localhost
OPENEDX_API_CLIENT_ID: fake_client_id
OPENEDX_API_CLIENT_SECRET: fake_client_secret
OPENEDX_API_KEY: test-openedx-api-key # pragma: allowlist secret
OPENEDX_API_CLIENT_SECRET: fake_client_secret # pragma: allowlist secret
OPENEDX_API_KEY: test-openedx-api-key # pragma: allowlist secret

- name: Tests
run: |
export MEDIA_ROOT="$(mktemp -d)"
poetry run ./scripts/test/python_tests.sh
env:
DEBUG: False
NODE_ENV: 'production'
CELERY_TASK_ALWAYS_EAGER: 'True'
NODE_ENV: "production"
CELERY_TASK_ALWAYS_EAGER: "True"
CELERY_BROKER_URL: redis://localhost:6379/4
CELERY_RESULT_BACKEND: redis://localhost:6379/4
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres # pragma: allowlist secret
WEBPACK_DISABLE_LOADER_STATS: 'True'
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres # pragma: allowlist secret
WEBPACK_DISABLE_LOADER_STATS: "True"
ELASTICSEARCH_URL: localhost:9200
MAILGUN_KEY: fake_mailgun_key
MAILGUN_SENDER_DOMAIN: other.fake.site
MITOL_DIGITAL_CREDENTIALS_VERIFY_SERVICE_BASE_URL: http://localhost:5000
MITOL_DIGITAL_CREDENTIALS_HMAC_SECRET: fake.hmac.secret
MITOL_DIGITAL_CREDENTIALS_HMAC_SECRET: fake.hmac.secret # pragma: allowlist secret
MITOL_HUBSPOT_API_PRIVATE_TOKEN: test-token
MITXPRO_ADMIN_EMAIL: example@localhost
MITXPRO_BASE_URL: http://localhost:8053
MITXPRO_DB_DISABLE_SSL: 'True'
MITXPRO_DB_DISABLE_SSL: "True"
MITXPRO_EMAIL_BACKEND: django.core.mail.backends.locmem.EmailBackend
MITXPRO_NOTIFICATION_EMAIL_BACKEND: django.core.mail.backends.locmem.EmailBackend
MITXPRO_SECURE_SSL_REDIRECT: 'False'
MITXPRO_USE_S3: 'False'
MITXPRO_SECURE_SSL_REDIRECT: "False"
MITXPRO_USE_S3: "False"
OPENEDX_API_BASE_URL: http://localhost:18000
OPENEDX_API_CLIENT_ID: fake_client_id
OPENEDX_API_CLIENT_SECRET: fake_client_secret
OPENEDX_API_KEY: test-openedx-api-key # pragma: allowlist secret
SECRET_KEY: local_unsafe_key # pragma: allowlist secret
OPENEDX_API_CLIENT_SECRET: fake_client_secret # pragma: allowlist secret
OPENEDX_API_KEY: test-openedx-api-key # pragma: allowlist secret
SECRET_KEY: local_unsafe_key # pragma: allowlist secret

- name: Upload coverage to CodeCov
uses: codecov/codecov-action@v3
Expand All @@ -142,11 +136,11 @@ jobs:
- name: Setup NodeJS
uses: actions/setup-node@v2-beta
with:
node-version: 15.14.0
node-version: 15.14.0

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT

- uses: actions/cache@v1
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
Expand All @@ -159,13 +153,13 @@ jobs:
run: yarn install --immutable

- name: Lints
run: npm run lint
run: npm run lint-check

- name: Code formatting
run: npm run fmt:check

- name: Scss lint
run: npm run scss_lint
run: npm run scss-lint

- name: Flow
run: npm run flow
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/new-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ on:
jobs:
add-to-hq:
uses: mitodl/ol-github-workflows/.github/workflows/add-to-ol-hq.yaml@main
secrets: inherit
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/release-candiate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:
github.event_name == 'workflow_dispatch' ||
github.event.workflow_run.conclusion == 'failure'
steps:
- run: echo 'The triggering workflow failed'
- run: echo 'The triggering workflow failed'
2 changes: 1 addition & 1 deletion .istanbul.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
instrumentation:
excludes: ['**/*_test.js']
excludes: ["**/*_test.js"]
112 changes: 107 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,109 @@
---
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
ci:
skip:
# Because these are local hooks it seems like they won't easily run in pre-commit CI
- prettier
- eslint
- stylelint
repos:
- repo: git@github.com:Yelp/detect-secrets
rev: v0.13.1
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: detect-secrets
args: ['--baseline', '.secrets.baseline']
exclude: .*_test.*|yarn\.lock
- id: trailing-whitespace
- id: end-of-file-fixer
exclude: ".hbs$"
- id: check-yaml
- id: check-added-large-files
- id: check-merge-conflict
- id: check-toml
- id: debug-statements
- repo: https://github.com/scop/pre-commit-shfmt
rev: v3.8.0-1
hooks:
- id: shfmt
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
hooks:
- id: yamllint
args: [--format, parsable, -d, relaxed]
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
args:
- --baseline
- .secrets.baseline
- --exclude-files
- .yarn/
- --exclude-files
- "_test.py$"
- --exclude-files
- "test_.*.py"
- --exclude-files
- poetry.lock
- --exclude-files
- yarn.lock
- --exclude-files
- compliance/test_data/cybersource/
- --exclude-files
- "_test.js$"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.4.0"
hooks:
- id: ruff-format
- id: ruff
args:
- --extend-ignore=D1
- --fix
- repo: local
hooks:
- id: prettier
name: Prettier
language: node
entry: yarn
args: [run, prettier, --write, --ignore-unknown]
types_or:
[
javascript,
jsx,
ts,
tsx,
json,
scss,
sass,
css,
yaml,
markdown,
html,
]
- id: eslint
name: eslint
description: "Lint JS/TS files and apply automatic fixes"
entry: yarn
language: node
types_or: [javascript, jsx, ts, tsx]
args: [run, eslint, --fix, --quiet]
exclude: "(node_modules/|.yarn/)"
require_serial: false
- id: stylelint
name: stylelint
description: "Lint SCSS files"
entry: yarn
language: node
types_or: [scss, css, sass]
args: [run, stylelint, --allow-empty-input, --fix]
exclude: "(node_modules/|static/css/vendor/)"
require_serial: false
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.10.0.1
hooks:
- id: shellcheck
args: ["--severity=warning"]
- repo: https://github.com/rhysd/actionlint
rev: v1.6.27
hooks:
- id: actionlint
name: actionlint
description: Runs actionlint to lint GitHub Actions workflow files
15 changes: 15 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.venv/
.yarn/
flow-typed/npm/
static/js/flow/
static/js/components/forms/elements/FormError.js
static/js/lib/queries/catalog.js
static/js/containers/pages/profile/ViewProfilePage.js
static/js/lib/courses.js
static/js/store/configureStore.js
static/js/util/integration_test_helper.js
static/js/lib/queries/digitalCredentials.js
static/js/Router.js
static/js/components/forms/ProfileFormFields.js
voucher/templates/enroll.html
mail/templates/product_order_receipt/body.html
11 changes: 11 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "http://json.schemastore.org/prettierrc",
"semi": true,
"overrides": [
{
"files": "**/*.js",
"parser": "flow"
}
],
"plugins": ["prettier-plugin-django-alpine"]
}
11 changes: 4 additions & 7 deletions .sass-lint.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
options:
merge-default-rules: false
files:
include: 'static/scss/**/*.scss'
include: "static/scss/**/*.scss"
rules:
extends-before-mixins: 2
extends-before-declarations: 2
Expand All @@ -25,15 +25,12 @@ rules:
space-before-bang: 2
hex-notation:
- 2
-
style: lowercase
- style: lowercase
indentation:
- 2
-
size: 2
- size: 2
brace-style:
- 2
-
allow-single-line: false
- allow-single-line: false
empty-line-between-blocks: 2
space-before-brace: 2
Loading

0 comments on commit dfcc797

Please sign in to comment.