npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@primer/stylelint-diff-filter

v1.0.0

Published

Filter stylelint reports by files changed in git

Downloads

371

Readme

stylelint-diff-filter

This is a stylelint formatter that filters reports so that they only include warnings occurring on files and lines in a related git diff. Specifically, only the results that satisfy the following tests will be passed through to the configured formatter:

  1. Files whose path is included in the diff
  2. Warnings on lines included in the diff

The primary use case of this module is a log parser that automatically converts predictably formatted error messages into check annotations on GitHub.

Install

npm install -D @primer/stylelint-diff-filter

Usage

You can use this reporter via the stylelint CLI with:

stylelint --custom-formatter=@primer/stylelint-diff-filter

If you use it this way, you'll likely want to configure it.

Diffs

Without any configuration, stylelint-diff-filter obtains a diff by shelling out to git diff -U1 <ref>, where the <ref> default is master. The -U1 flag tells git to only output one line of "context" rather than the default three, which should be slightly faster to process.

The diff output is parsed with what-the-diff into an array of objects that represent diffs for individual files that may or may not have been renamed, each of which has one or more "hunks" that reference a start line number, line count, and one or more lines of diff text output.

Configuration

[Stylelint formatters] can't be configured via stylelint configuration files. Rather than implementing its own customization system, stylelint-diff-filter offers configuration via the following environment variables:

STYLELINT_DIFF

If provided, specifies the git diff output to parse instead of calling git diff -U1 <base> internally. This can be helpful in large codebases where you only want to parse the diff of the directory containing CSS files:

lint_path=app/assets/stylesheets
export STYLELINT_DIFF=$(git diff -U1 master -- $lint_path)
npx stylelint --custom-formatter=@primer/stylelint-diff-filter $lint_path

STYLELINT_DIFF_BASE

This allows you to specify a git ref against which to diff in the git diff -U1 <ref> call (assuming STYLELINT_DIFF is unset). The default is master. For example:

export STYLELINT_DIFF_BASE=release-1.0.0
npx stylelint --custom-formatter=@primer/stylelint-diff-filter

####STYLELINT_DIFF_FORMATTER Specifies which stylelint formatter to call with the filtered results. This can take a couple of different forms:

  1. The name of one of stylelint's built-in formatters: string (the default), compact, json, or verbose
  2. The path or name of a node module to require().

For example, to use the JSON formatter:

export STYLELINT_DIFF_FORMATTER=json
stylelint --custom-formatter=@primer/stylelint-diff-filter --quiet > errors.json

API

The main export of @primer/stylelint-diff-filter is a function that takes a result and an optional object of options:

  • cwd is the current working directory, which is used to strip prefixes from filenames in the diff to match what stylelint reports.
  • base is the ref against which to git diff, which defaults to STYLELINT_DIFF_BASE or master.
  • diff is the git diff output to parse, which defaults to STYLELINT_DIFF or the output of git diff -U1 <base>.
  • formatter is the path or name of the stylelint formatter with which to format the filtered results, and defaults to STYLELINT_DIFF_FORMATTER or string (stylelint's own default).

Example

You may find it simpler to provide your own custom formatter that calls @primer/stylelint-diff-filter itself:

// reporter.js
const diff = require('@primer/stylelint-diff-filter')
const myAwesomeFormatter = require('./path/to/awesome-formatter')
module.exports = results => diff(results, {
  formatter: myAwesomeFormatter
})

...which you would then use with:

npx stylelint --custom-formatter=path/to/reporter.js

License

MIT © GitHub