You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The lint command takes around 10 seconds to run. This is fine when it's run on CI, but it feels a bit uncomfortable when run as a part of a push.
Ideally, what we want is something like this:
Full run (check or fix):
Run ESLint on all *.js and *.ts files, omitting those in .gitignore
Run Prettier on all *.json, *.md, and *.yml files, omitting those in .gitignore, as well as CHANGELOG.mds in any packages, CHANGELOG.old.md, and .yarnrc.yml
Partial run (changed files only):
Run ESLint on all changed*.js and *.ts files, omitting those in .gitignore
Run Prettier on all changed*.json, *.md, and *.yml files, omitting those in .gitignore, as well as CHANGELOG.mds in any packages, CHANGELOG.old.md, and .yarnrc.yml
More details below:
The Snaps monorepo attempts to reduce the runtime by using lint-staged to only linting files that have been staged. There are two wrinkles with the approach that the Snaps monorepo takes that would prevent us from copying it to this repo, however.
First, lint-staged is designed to be paired with a pre-commit hook, but we use a pre-push hook instead, so we'd need a different solution. So minimally, we could use something like lint-changed instead.
However, lint-changed (and lint-staged, for that matter) assume that you don't want to customize the set of files that are processed when running a full lint. For ESLint, that's not a problem, as we can get away with asking it to lint the whole project and then use .gitignore to filter out undesired files. Prettier, however, doesn't use .gitignore by default, so we tell it to use .gitignore, but then we also filter out more files on top of that.
So if we were to start using lint-changed, we'd have to have a separate way of running Prettier. We'd need a way to run file paths that lint-changed has reported as changed, but continue to filter out undesired files that aren't covered by .gitignore.
The Prettier team has made this somewhat easier by allowing multiple ignore file paths to be passed: prettier/prettier#14332. So we could pull out the list of files that we're excluding to a .prettierignore and then instruct the prettier command to use that in addition to .gitignore.
However, one problem would remain: we'd have to accommodate two ways of calling — and configuring — our lint commands.
Say we were able to reduce package.json to something like this:
(We don't specify any file paths for lint-staged because it fills them in for us.)
Note how we have to specify two ways of running the eslint and prettier commands, and we have to specify acceptable file extensions twice. It'd be nice if we could just say:
The
lint
command takes around 10 seconds to run. This is fine when it's run on CI, but it feels a bit uncomfortable when run as a part of a push.Ideally, what we want is something like this:
*.js
and*.ts
files, omitting those in.gitignore
*.json
,*.md
, and*.yml
files, omitting those in.gitignore
, as well asCHANGELOG.md
s in any packages,CHANGELOG.old.md
, and.yarnrc.yml
*.js
and*.ts
files, omitting those in.gitignore
*.json
,*.md
, and*.yml
files, omitting those in.gitignore
, as well asCHANGELOG.md
s in any packages,CHANGELOG.old.md
, and.yarnrc.yml
More details below:
The Snaps monorepo attempts to reduce the runtime by using
lint-staged
to only linting files that have been staged. There are two wrinkles with the approach that the Snaps monorepo takes that would prevent us from copying it to this repo, however.First,
lint-staged
is designed to be paired with apre-commit
hook, but we use apre-push
hook instead, so we'd need a different solution. So minimally, we could use something likelint-changed
instead.However,
lint-changed
(andlint-staged
, for that matter) assume that you don't want to customize the set of files that are processed when running a full lint. For ESLint, that's not a problem, as we can get away with asking it to lint the whole project and then use.gitignore
to filter out undesired files. Prettier, however, doesn't use.gitignore
by default, so we tell it to use.gitignore
, but then we also filter out more files on top of that.So if we were to start using
lint-changed
, we'd have to have a separate way of running Prettier. We'd need a way to run file paths thatlint-changed
has reported as changed, but continue to filter out undesired files that aren't covered by.gitignore
.The Prettier team has made this somewhat easier by allowing multiple ignore file paths to be passed: prettier/prettier#14332. So we could pull out the list of files that we're excluding to a
.prettierignore
and then instruct theprettier
command to use that in addition to.gitignore
.However, one problem would remain: we'd have to accommodate two ways of calling — and configuring — our lint commands.
Say we were able to reduce
package.json
to something like this:Now say we were to add
lint-changed
. That might look something like this:(We don't specify any file paths for
lint-staged
because it fills them in for us.)Note how we have to specify two ways of running the
eslint
andprettier
commands, and we have to specify acceptable file extensions twice. It'd be nice if we could just say:To get this to work, such a lint script would have to:
.
if no file patterns were specified, and pass the result off to the toolSo this ticket depends on the release of Prettier 3.0, but it also depends on writing such a lint script.
The text was updated successfully, but these errors were encountered: