Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync all pre-commit configs from this repo #334

Merged
merged 18 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .eslintignore
Empty file.
6 changes: 0 additions & 6 deletions .flake8

This file was deleted.

28 changes: 27 additions & 1 deletion .github/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,34 @@ group:
dest: .github/PULL_REQUEST_TEMPLATE.md
# Unified lint rules
- repos: |
WordPress/openverse
WordPress/openverse-catalog
WordPress/openverse-api
files:
- source: .pre-commit-config.yaml
- source: prettier.config.js.jinja
dest: prettier.config.js
template: true
- repos: |
WordPress/openverse
files:
- source: .pre-commit-config.local.yaml.jinja
dest: .pre-commit-config.yaml
template: true
- repos: |
WordPress/openverse-catalog
WordPress/openverse-api
files:
- source: .pre-commit-config.yaml.jinja
dest: .pre-commit-config.yaml
template:
contains_js_code: false
- repos: |
WordPress/openverse-frontend
files:
- source: .pre-commit-config.frontend.yaml.jinja
dest: .pre-commit-config.yaml
template:
contains_python_code: false
- source: prettier.config.frontend.js.jinja
dest: prettier.config.js
template: true
22 changes: 20 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,26 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup just
uses: extractions/setup-just@v1

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Setup pnpm
uses: pnpm/[email protected]

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16
cache: pnpm
cache-dependency-path: |
pnpm-lock.yaml
.npmrc

- name: Cache pre-commit envs
uses: actions/cache@v3
with:
Expand All @@ -34,5 +49,8 @@ jobs:

- name: Run pre-commit to lint files
run: |
pip install pre-commit
pre-commit run --all-files
pip install -U pip
pip install pipenv
just install
just precommit
just lint
72 changes: 72 additions & 0 deletions .pre-commit-config.frontend.yaml.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{% set eslint_files = '\\.(js|ts|vue)$' %}
{% set eslint_exclude = '^nuxt-template-overrides/.*$' %}

{% extends '.pre-commit-config.yaml.jinja' %}

{% block note %}
{{ super() }}
# - https://github.com/WordPress/openverse/blob/main/.pre-commit-config.frontend.yaml.jinja
{%- endblock %}

{#=======================================
Repo blocks must be indented by 2 spaces.
=======================================#}

{% block repos_top %}
- repo: local # More local hooks are defined at the bottom.
hooks:
- id: i18n
name: i18n
# Check if the i18n files have been downloaded by checking if the Arabic translation exists
# Download the i18n files if they do not exist
entry: bash -c 'if [ ! -f "$(dirname "$dir")"/src/locales/ar.json ]; then pnpm i18n; fi'
language: system
pass_filenames: false
{# This comment adds a blank line. #}
{% endblock %}

{% block repos_bottom %}
{# This comment adds a blank line. #}
- repo: local # More local hooks are defined at the top.
hooks:
- id: types
name: types
entry: bash -c 'pnpm types'
language: system
pass_filenames: false

- id: test:unit
name: test:unit
entry: bash -c 'pnpm test:unit'
language: system
pass_filenames: false
stages:
- push
{% endblock %}

{#=========================================
Dependencies must be indented by 10 spaces.
=========================================#}

{% block eslint_dependencies %}
{{ super() }}
- '@babel/[email protected]'
- '@intlify/[email protected]'
- '@nuxtjs/[email protected]'
- '@typescript-eslint/[email protected]'
- '@typescript-eslint/[email protected]'
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
{%- endblock %}

{% block prettier_dependencies %}
{{ super() }}
- [email protected]
- [email protected]
{%- endblock %}
23 changes: 23 additions & 0 deletions .pre-commit-config.local.yaml.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% extends '.pre-commit-config.yaml.jinja' %}

{% block note %}
{{ super() }}
# - https://github.com/WordPress/openverse/blob/main/.pre-commit-config.local.yaml.jinja
{%- endblock %}

{% block repos_bottom %}
{# This comment adds a blank line. #}
- repo: local
hooks:
- id: render-precommit
name: render-precommit
entry: bash -c 'just render-precommit'
language: system
pass_filenames: false

- id: render-prettier
name: render-prettier
entry: bash -c 'just render-prettier'
language: system
pass_filenames: false
{% endblock %}
53 changes: 41 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# This file is being synced from WordPress/openverse. Any changes made to it
# here will be overwritten. Please make any necessary edits to these files:
# - https://github.com/WordPress/openverse/blob/main/.pre-commit-config.yaml.jinja
# - https://github.com/WordPress/openverse/blob/main/.pre-commit-config.local.yaml.jinja

exclude: Pipfile\.lock|migrations|\.idea|node_modules|archive

repos:
Expand All @@ -6,36 +11,34 @@ repos:
hooks:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
exclude: tsconfig.json # contains comments
- id: check-case-conflict
- id: check-toml
- id: check-merge-conflict
- id: check-xml
- id: check-yaml
- id: end-of-file-fixer
exclude: test/tapes/.+\.json5
- id: check-symlinks
- id: mixed-line-ending
- id: fix-encoding-pragma
args:
- --remove
- id: check-docstring-first
- id: requirements-txt-fixer

# Use the `.isort.cfg` file to configure additional project-specific requirements.
- repo: https://github.com/PyCQA/isort
rev: 5.9.1
hooks:
- id: isort
files: \.py$
exclude: ^build/.*$|^.tox/.*$|^venv/.*$
args:
- --profile=black
- --lines-after-imports=2
- --multi-line=3
- --trailing-comma
- --force-grid-wrap=0
- --use-parentheses
- --ensure-newline-before-comments
- --line-length=88

- repo: https://github.com/asottile/pyupgrade
rev: v3.2.2
Expand All @@ -44,10 +47,14 @@ repos:
args:
- --py310-plus

# Use the `.flake8` file to configure additional project-specific requirements.
- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
args:
- --extend-ignore=E203,W503
- --max-line-length=88

- repo: https://github.com/ambv/black
rev: 22.3.0
Expand All @@ -57,21 +64,43 @@ repos:
- --safe

- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.3.0
rev: v8.15.0
hooks:
- id: eslint
files: ^js/.*$
'types': [file] # ESLint only accepts [javascript] by default.
args:
- --ignore-path=.gitignore
- --ignore-path=.eslintignore
- --max-warnings=0
additional_dependencies:
- eslint@8.3.0
- eslint-config-prettier@8.3.0
- eslint@8.15.0
- eslint-config-prettier@8.5.0

# Use the `.prettierignore` and `.prettier.config.js` files to configure project-specific requirements.
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.5.0
rev: v2.6.0
hooks:
- id: prettier
exclude: .*\.md$
exclude: \.md$ # TODO: https://github.com/WordPress/openverse/issues/333
additional_dependencies:
- [email protected]

- repo: https://github.com/koalaman/shellcheck-precommit
rev: v0.8.0
hooks:
- id: shellcheck

- repo: local
hooks:
- id: render-precommit
name: render-precommit
entry: bash -c 'just render-precommit'
language: system
pass_filenames: false

- id: render-prettier
name: render-prettier
entry: bash -c 'just render-prettier'
language: system
pass_filenames: false
Loading