From 58e757cda240994ea6ac0d4afa5d31ba2f10d7a2 Mon Sep 17 00:00:00 2001 From: Ali Sajid Imami <395482+AliSajid@users.noreply.github.com> Date: Thu, 5 Dec 2024 12:09:25 -0500 Subject: [PATCH 1/2] feat: add a pre-commit hook Signed-off-by: Ali Sajid Imami <395482+AliSajid@users.noreply.github.com> --- README.md | 9 +++++++++ pre-commit-hooks.yaml | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 pre-commit-hooks.yaml diff --git a/README.md b/README.md index 1382ff1..bc0480a 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,15 @@ Rules: alt="Sponsored by Evil Martians" width="236" height="54"> +## Pre-Commit Hook + +This project is also available as a pre-commit hook. Please add the following to your pre-commit configuration. + +```yaml +repos: + - repo: https://github.com/browserslist/lint + id: browserslist-lint +``` ## JS API diff --git a/pre-commit-hooks.yaml b/pre-commit-hooks.yaml new file mode 100644 index 0000000..cc92497 --- /dev/null +++ b/pre-commit-hooks.yaml @@ -0,0 +1,16 @@ +# Define the hooks available in this repository +- id: browserslist-lint + name: Validate Browserslist Configuration + # Command to execute the linter using npx for local installation + entry: npx browserslist-linter + # Specify the language for the hook; 'node' is used for npm-based tools + language: node + # Regular expression to match files that should trigger the hook + # The hook will run if `.browserslistrc` or `package.json` is modified + files: ^(\.browserslistrc|package\.json)$ + # Disable passing filenames as arguments since the linter inspects its own targets + pass_filenames: false + # Run the hook only when relevant files are modified, not always + always_run: false + # Description of the hook to inform users about its purpose + description: Validate Browserslist configuration using browserslist-linter. From 0ddd4fa86fb1996ebef194b2b9bc8c4ba7833f50 Mon Sep 17 00:00:00 2001 From: Ali Sajid Imami <395482+AliSajid@users.noreply.github.com> Date: Thu, 5 Dec 2024 14:20:58 -0500 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Andrey Sitnik --- pre-commit-hooks.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pre-commit-hooks.yaml b/pre-commit-hooks.yaml index cc92497..d268cc6 100644 --- a/pre-commit-hooks.yaml +++ b/pre-commit-hooks.yaml @@ -2,15 +2,15 @@ - id: browserslist-lint name: Validate Browserslist Configuration # Command to execute the linter using npx for local installation - entry: npx browserslist-linter + entry: npx browserslist-lint # Specify the language for the hook; 'node' is used for npm-based tools language: node # Regular expression to match files that should trigger the hook # The hook will run if `.browserslistrc` or `package.json` is modified - files: ^(\.browserslistrc|package\.json)$ + files: (\.browserslistrc|package\.json)$ # Disable passing filenames as arguments since the linter inspects its own targets pass_filenames: false # Run the hook only when relevant files are modified, not always always_run: false # Description of the hook to inform users about its purpose - description: Validate Browserslist configuration using browserslist-linter. + description: Validate Browserslist configuration using browserslist-lint.