0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-04 10:39:43 +08:00
discourse/lefthook.yml
Sérgio Saquetim 79b187189c
DEV: Lint .mjs and .cjs files locally (#42110)
`bin/lint` currently filters out `.mjs` and `.cjs` before Lefthook runs,
even though CI ESLint checks them. CI Prettier has the opposite gap and
skips them.

This includes both extensions in `bin/lint`, Lefthook's ESLint globs,
and the Prettier scripts for frontend, plugins, and themes.
2026-07-29 16:23:50 -03:00

189 lines
5.4 KiB
YAML
Vendored

output:
- summary
- empty_summary
- failure
- execution
- execution_out
- execution_info
- skips
glob_matcher: doublestar
pre-commit:
parallel: true
skip:
- merge
- rebase
commands:
rubocop:
exclude: &ruby_exclude
- "bin/notify_file_change"
- "bin/docker/**/*"
glob: &ruby_glob
- "**/*.{rb,rake,thor}"
- "bin/**/*"
- "Gemfile"
run: bundle exec rubocop --force-exclusion {staged_files}
syntax_tree:
exclude: *ruby_exclude
glob: *ruby_glob
run: bundle exec stree check Gemfile {staged_files}
prettier:
glob: &prettier_glob
- "app/assets/stylesheets/**/*.{css,scss}"
- "frontend/**/*.{js,gjs,ts,gts,mts,cts,scss,css,cjs,mjs}"
- "plugins/**/*.{js,gjs,ts,gts,mts,cts,scss,css,cjs,mjs}"
- "themes/**/*.{js,gjs,ts,gts,mts,cts,scss,css,cjs,mjs}"
run: pnpm pprettier --list-different {staged_files}
eslint:
glob: &eslint_glob
- "frontend/**/*.{js,gjs,ts,gts,mts,cts,cjs,mjs}"
- "plugins/**/*.{js,gjs,ts,gts,mts,cts,cjs,mjs}"
- "themes/**/*.{js,gjs,ts,gts,mts,cts,cjs,mjs}"
run: pnpm eslint --max-warnings 0 {staged_files}
yaml-syntax:
glob: &yaml_glob "**/*.{yaml,yml}"
# database.yml is an erb file not a yaml file
exclude: &yaml_exclude "config/database.yml"
run: bundle exec yaml-lint {staged_files}
i18n-lint:
glob: &i18n_glob "**/{client,server}.en.yml"
run: bundle exec ruby script/i18n_lint.rb {staged_files}
stylelint:
glob: &stylelint_glob
- "app/assets/stylesheets/**/*.scss"
- "plugins/**/assets/stylesheets/**/*.scss"
- "themes/**/*.scss"
run: pnpm stylelint {staged_files}
fix-staged:
parallel: false
commands:
prettier:
glob: *prettier_glob
run: pnpm pprettier --write {staged_files}
eslint:
glob: *eslint_glob
run: pnpm eslint --fix {staged_files}
stylelint:
glob: *stylelint_glob
run: pnpm stylelint --fix {staged_files}
rubocop:
exclude: *ruby_exclude
glob: *ruby_glob
run: bundle exec rubocop --force-exclusion -A {staged_files}
syntax_tree:
exclude: *ruby_exclude
glob: *ruby_glob
run: bundle exec stree write Gemfile {staged_files}
# Working-tree counterparts of pre-commit/fix-staged. Deliberately NOT named
# pre-commit/pre-push so lefthook does not hide unstaged changes: the linters
# read the files exactly as they are on disk, not their staged blobs. bin/lint
# routes explicit-path, --recent, --unstaged and --wip runs here. The {files}
# template is overridden by the --file flag bin/lint passes; the files command
# is only the fallback when no --file is given and lists tracked plus untracked
# (but not ignored) paths.
lint-files:
parallel: true
commands:
rubocop:
files: &working_tree_files git ls-files --cached --others --exclude-standard
exclude: *ruby_exclude
glob: *ruby_glob
run: bundle exec rubocop --force-exclusion {files}
syntax_tree:
files: *working_tree_files
exclude: *ruby_exclude
glob: *ruby_glob
run: bundle exec stree check Gemfile {files}
prettier:
files: *working_tree_files
glob: *prettier_glob
run: pnpm pprettier --list-different {files}
eslint:
files: *working_tree_files
glob: *eslint_glob
run: pnpm eslint --max-warnings 0 {files}
yaml-syntax:
files: *working_tree_files
glob: *yaml_glob
exclude: *yaml_exclude
run: bundle exec yaml-lint {files}
i18n-lint:
files: *working_tree_files
glob: *i18n_glob
run: bundle exec ruby script/i18n_lint.rb {files}
stylelint:
files: *working_tree_files
glob: *stylelint_glob
run: pnpm stylelint {files}
fix-files:
parallel: false
commands:
prettier:
files: *working_tree_files
glob: *prettier_glob
run: pnpm pprettier --write {files}
eslint:
files: *working_tree_files
glob: *eslint_glob
run: pnpm eslint --fix {files}
stylelint:
files: *working_tree_files
glob: *stylelint_glob
run: pnpm stylelint --fix {files}
rubocop:
files: *working_tree_files
exclude: *ruby_exclude
glob: *ruby_glob
run: bundle exec rubocop --force-exclusion -A {files}
syntax_tree:
files: *working_tree_files
exclude: *ruby_exclude
glob: *ruby_glob
run: bundle exec stree write Gemfile {files}
fix-all:
parallel: false
commands:
prettier:
run: pnpm lint:prettier:fix
eslint:
run: pnpm lint:js:fix
stylelint:
run: pnpm lint:css:fix
rubocop:
run: bundle exec rubocop --force-exclusion -A
syntax_tree:
exclude: *ruby_exclude
glob: *ruby_glob
run: bundle exec stree write Gemfile {all_files}
lints:
parallel: true
commands:
rubocop:
glob: *ruby_glob
run: bundle exec rubocop
syntax_tree:
exclude: *ruby_exclude
glob: *ruby_glob
run: bundle exec stree check Gemfile {all_files}
prettier:
run: pnpm lint:prettier
eslint:
run: pnpm lint:js
stylelint:
run: pnpm lint:css
yaml-syntax:
glob: *yaml_glob
# database.yml is an erb file not a yaml file
exclude: *yaml_exclude
run: bundle exec yaml-lint {all_files}
i18n-lint:
glob: *i18n_glob
run: bundle exec ruby script/i18n_lint.rb {all_files}
glint:
run: pnpm lint:types