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

feat: add a pre-commit hook #8

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ Rules:
alt="Sponsored by Evil Martians" width="236" height="54">
</a>

## Pre-Commit Hook

This project is also available as a pre-commit hook. Please add the following to your pre-commit configuration.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s add link here. pre-commit is a popular name, there are many projects with this name. People will now understand it without a link.


```yaml
repos:
- repo: https://github.com/browserslist/lint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s use 2 space indents to have consistent code style

id: browserslist-lint
```

## JS API

Expand Down
16 changes: 16 additions & 0 deletions pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -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-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)$
# 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-lint.