GithubHelp home page GithubHelp logo

lint-changed's Introduction

@artsy/lint-changed

This package is inspired heavily by lint-staged. Also checkout pull-lock.

We waste a lot of time of CI time doing unnecessary tasks. Why lint all your files when git already tells you which files have changed? @artsy/lint-changed helps by only running lint tags for the files that have changed since main (when not on main) or since the last tag (if you are on main).

Installation

yarn add -D @artsy/lint-changed

The general purpose of this library is to run on CI, to reduce the amount of time between runs. It's similar to lint-staged in that it will take a list files that have changed (the diff between main branch and a PR, for example) and pipe them into a command. So rather than running all tests on CI one could instead run just the tests that have changed. See below for an example as well as the example app.

Basic Configuration

Add a lint-changed key to your package.json with a pattern of files to match and the command or commands you'd like to run for each changed file. Each command will be ran for every changed file that matches it's pattern.

{
  "lint-changed": {
    "*.js": ["eslint", "prettier -c"],
    "*.ts": "tslint",
    "*.test.ts": "jest" 
  }
}

And then add a new package.json script to run lint-changed on CI:

{
  "scripts": {
    "ci": "yarn lint-changed"
  }
}

For the given configuration above if the following three files were changed...

foo.js
bar.ts
baz.json
bam.test.ts

You could expect the following commands to be ran

eslint foo.js
prettier -c foo.js
tslint bar.ts
jest bam.test.ts

Note that baz.json would be skipped because it doesn't match with any patterns in the configuration.

Configuring base branch

By default Artsy will use main as the base branch for detecting changes. In case your default branch is not main you can let Artsy know what branch to use as a base branch.

{
  "lint-changed-base-branch": "development",
  "lint-changed": {
    "*.js": ["eslint", "prettier -c"],
    "*.ts": "tslint"
  }
}

About Artsy

This project is the work of engineers at Artsy, the world's leading and largest online art marketplace and platform for discovering art. One of our core Engineering Principles is being Open Source by Default which means we strive to share as many details of our work as possible.

You can learn more about this work from our blog and by following @ArtsyOpenSource or explore our public data by checking out our API. If you're interested in a career at Artsy, read through our job postings!

lint-changed's People

Contributors

artsyit avatar zephraph avatar renovate-bot avatar damassi avatar renovate[bot] avatar alexanderjeurissen avatar recuencojones avatar icirellik avatar starsirius avatar ds300 avatar joeyaghion avatar dependabot[bot] avatar

Stargazers

Minho Ryang avatar Renzy Ortega avatar Sung Jeon avatar lbb avatar Hendry Sadrak avatar  avatar JuanP Barba avatar ivan avatar  avatar Minho Ryang avatar Alex Davydenko avatar  avatar  avatar  avatar

Watchers

 avatar  avatar Andre Rocha avatar Oksana avatar Fladson Gomes avatar  avatar James Cloos avatar Dejan avatar Ashkan Nasseri avatar Anson Wang avatar Matt Zikherman avatar Sarah Weir avatar Ole avatar Christina avatar Lily Pace avatar Samuel Rozenberg avatar Joel Rosenblatt avatar  avatar Nick Spinazze avatar Jacqueline Potts avatar Emma Dickson avatar  avatar Carlos avatar Tam avatar Kizito Egeonu avatar Danger avatar Sultan Al-Maari avatar TanjieM avatar  avatar Adam Iskounen avatar

lint-changed's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository. View logs.

  • WARN: Using npm packages for Renovate presets is now deprecated. Please migrate to repository-based presets instead.

Pending Approval

These branches will be created by Renovate only once you click their checkbox below.

  • chore(deps): pin dependencies (jest, prettier)
  • chore(deps): update dep @types/micromatch from 4.0.1 to v4.0.7
  • chore(deps): update dep @types/node from 13.7.7 to v13.13.52
  • chore(deps): update dep typescript from 5.2.2 to v5.4.5
  • chore(deps): update dep @types/node from 13.7.7 to v20
  • chore(deps): update dep await-to-js from 2.1.1 to v3
  • chore(deps): update dep commander from 8.0.0 to v12
  • chore(deps): update dep jest from 28.1.3 to v29
  • chore(deps): update dep kleur from 3.0.3 to v4
  • chore(deps): update dep p-limit from 2.3.0 to v5
  • chore(deps): update dep prettier from 2.7.1 to v3
  • ๐Ÿ” Create all pending approval PRs at once ๐Ÿ”

Detected dependencies

circleci
.circleci/config.yml
  • yarn 6.5.0
  • auto 2.2.0
npm
example/package.json
  • @artsy/lint-changed 5.3.0
  • jest ^28.1.3
  • prettier ^2.7.1
package.json
  • await-to-js ^2.1.1
  • commander ^8.0.0
  • kleur ^3.0.3
  • micromatch ^4.0.2
  • p-limit ^2.2.2
  • @artsy/auto-config 1.2.0
  • @types/micromatch 4.0.1
  • @types/node 13.7.7
  • typescript 5.2.2

  • Check this box to trigger a request for Renovate to run again on this repository

Warnings in eslint output treated as error

Some days ago while running some of our pipelines we started noticing our linter stage would fail running lint-changed.

Apparently, when running eslint under the hood, it would warn about browserslist:

Browserslist: caniuse-lite is outdated. Please run:
  npx browserslist@latest --update-db
  Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating

That statement seems to be logged via console.warn, which goes through stderr buffer and therefore makes lint-changed to fail with an empty red line.

image

This empty line is probably due to throwing a string and then destructuring in catch.

I'd assume only errors caught from await run() should actually make lint-staged fail.

Make base branch configurable

Props for this project, very cool indeed.

I was wondering if you've considered making the base branch that is compared against configurable.
For my use-case our main branch is develop and master is only used for releases.

Handle git warnings

Hey, I'm just trying out your tool :)

What I've got:

[lint-changed]: Unable to get changed files since main:
Error

What I found out via console.log:

stderr:  
stderr:  warning: inexact rename detection was skipped due to too many files.
warning: you may want to set your diff.renameLimit variable to at least 450 and retry the command.

So I see it's my git config issue, but imo:

  • tool should trim stderr before logic check to throw on actual error stderr
  • tool should probably skip (maybe print) warning: xxx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.