Skip to content

Lint git index content on commit#113300

Merged
cavokz merged 12 commits intoelastic:masterfrom
cavokz:eslint-run-on-commit-content
Oct 1, 2021
Merged

Lint git index content on commit#113300
cavokz merged 12 commits intoelastic:masterfrom
cavokz:eslint-run-on-commit-content

Conversation

@cavokz
Copy link
Copy Markdown
Contributor

@cavokz cavokz commented Sep 28, 2021

This fixes two fundamental issues:

  • the list of files to be linted is built looking at the diffs of the ref specified with --ref (or otherwise the current index) with those on the filesystem
  • the content to be linted is read from the filesystem instead of the specified --ref or the one in the index

This fixes two fundamental issues:
* the list of files to be linted is built looking at the diffs of the ref
  specified with `--ref` (or otherwise the current index) with those on
  the filesystem
* the content to be linted is read from the filesystem instead of the
  specified `ref` or the one in the index
@cavokz cavokz requested a review from a team as a code owner September 28, 2021 17:28
@cavokz cavokz added auto-backport Deprecated - use backport:version if exact versions are needed release_note:skip Skip the PR/issue when compiling release notes v7.15.0 v7.16.0 v8.0.0 labels Sep 28, 2021
Copy link
Copy Markdown
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

Thank you!! This is great

@cavokz
Copy link
Copy Markdown
Contributor Author

cavokz commented Sep 29, 2021

I'm a bit perplexed by this (from commit_check_runner.sh):

!!!!!!!! ATTENTION !!!!!!!!
That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook.
If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally'
!!!!!!!!!!!!!!!!!!!!!!!!!!!

Is in the plans to actually drop the pre-commit hook usage on dev's machines?

To me it looks beneficial and actually useful to intercept as early as possible any gating issue to the PR merging, which is why I tried to improve the status quo.

@cavokz cavokz enabled auto-merge (squash) September 29, 2021 14:20
@cavokz cavokz requested a review from spalger September 29, 2021 14:33
@spalger
Copy link
Copy Markdown
Contributor

spalger commented Sep 29, 2021

I'm a bit perplexed by this (from commit_check_runner.sh):

!!!!!!!! ATTENTION !!!!!!!!
That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook.
If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally'
!!!!!!!!!!!!!!!!!!!!!!!!!!!

Is in the plans to actually drop the pre-commit hook usage on dev's machines?

To me it looks beneficial and actually useful to intercept as early as possible any gating issue to the PR merging, which is why I tried to improve the status quo.

Yes, it's actually already done. The precommit hook isn't setup by default when you bootstrap. We found the precommit hook to mostly be annoying and that with good IDE integrations and auto-fix on save it seemed rather unnecessary. Though, like the message reads, users can opt into the precommit hook and have it installed. Additionally, we run the equivalent checks first on CI so that it can tell users as quickly as possible when they do have issues which would have been caught by the precommit hook (had they installed it).

const simpleGit = new SimpleGit(REPO_ROOT);
const gitRefForDiff = gitRef ? gitRef : '--cached';
const output = await fcb((cb) => simpleGit.diff(['--name-status', gitRefForDiff], cb));
const gitCatPrefix = gitRef ? gitRef + ':' : ':';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you think we could use a git command to resolve a git range to the latest sha so that we could pass things like --ref master^^...HEAD and then read the blobs from the sha pointed to by HEAD?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can check. I also see the value of specifying a range.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

With that use case in mind, I think that for the --ref usage I should simply revert to the original behavior. Which is, the range is used only to build the list of files. The linting is actually done on the files as-is on disk, effectively locking the right end of the range to HEAD.

Otherwise a given file would be linted as many time as the many commits that change it, possibly reporting problems that would otherwise elide in the whole range.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmmmmmm... I definitely think that we use the --ref more often to lint all the file that changed since a specific ref. I guess I just assumed that this would work that way too but maybe that was a bad assumption. Maybe we need to rename --ref or fix the --help text?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For instance, with the recent prettier update, we used it to help people --fix all the files that were modified in their PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do you think we could use a git command to resolve a git range to the latest sha so that we could pass things like --ref master^^...HEAD and then read the blobs from the sha pointed to by HEAD?

Forget my previous claims, I implemented this case ;)

@cavokz cavokz disabled auto-merge September 30, 2021 13:47
@cavokz
Copy link
Copy Markdown
Contributor Author

cavokz commented Sep 30, 2021

@elasticmachine merge upstream

@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@cavokz cavokz requested a review from spalger September 30, 2021 19:24
Copy link
Copy Markdown
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for your help making this better!

@cavokz cavokz merged commit 92fe7f8 into elastic:master Oct 1, 2021
@cavokz cavokz deleted the eslint-run-on-commit-content branch October 1, 2021 05:03
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 1, 2021
This fixes two fundamental issues:
* the list of files to be linted is built looking at the diffs of the ref
  specified with `--ref` (or otherwise the current index) with those on
  the filesystem
* the content to be linted is read from the filesystem instead of the
  specified `ref` or the one in the index
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 1, 2021
This fixes two fundamental issues:
* the list of files to be linted is built looking at the diffs of the ref
  specified with `--ref` (or otherwise the current index) with those on
  the filesystem
* the content to be linted is read from the filesystem instead of the
  specified `ref` or the one in the index
@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Backport successful

Status Branch Result
7.15
7.x

The backport PRs will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Oct 1, 2021
This fixes two fundamental issues:
* the list of files to be linted is built looking at the diffs of the ref
  specified with `--ref` (or otherwise the current index) with those on
  the filesystem
* the content to be linted is read from the filesystem instead of the
  specified `ref` or the one in the index

Co-authored-by: Domenico Andreoli <domenico.andreoli@elastic.co>
kibanamachine added a commit that referenced this pull request Oct 1, 2021
This fixes two fundamental issues:
* the list of files to be linted is built looking at the diffs of the ref
  specified with `--ref` (or otherwise the current index) with those on
  the filesystem
* the content to be linted is read from the filesystem instead of the
  specified `ref` or the one in the index

Co-authored-by: Domenico Andreoli <domenico.andreoli@elastic.co>
@spalger
Copy link
Copy Markdown
Contributor

spalger commented Oct 4, 2021

Sorry @cavokz, but it seems that scss linting is broken with this PR. I'm not sure what the issue is, but I'm going to need to revert this for now.

spalger added a commit that referenced this pull request Oct 4, 2021
spalger added a commit that referenced this pull request Oct 4, 2021
@cavokz
Copy link
Copy Markdown
Contributor Author

cavokz commented Oct 4, 2021

Sorry @cavokz, but it seems that scss linting is broken with this PR. I'm not sure what the issue is, but I'm going to need to revert this for now.

I'd like to understand what got broken. I tested it with scss files. Do you have a link for me?

spalger added a commit that referenced this pull request Oct 4, 2021
@spalger
Copy link
Copy Markdown
Contributor

spalger commented Oct 4, 2021

I was able to reproduce the issue in #113570, which is admittedly a large reproduction case, but you can reproduce it by trying to run the pre-commit hook on any scss file with // comments like src/plugins/presentation_util/public/components/solution_toolbar/items/button.scss

@cavokz
Copy link
Copy Markdown
Contributor Author

cavokz commented Oct 5, 2021

Sorry @cavokz, but it seems that scss linting is broken with this PR. I'm not sure what the issue is, but I'm going to need to revert this for now.

This was auto-backported to 7.x and 7.15, did you revert it from there as well?

@spalger
Copy link
Copy Markdown
Contributor

spalger commented Oct 12, 2021

Sorry @cavokz, but it seems that scss linting is broken with this PR. I'm not sure what the issue is, but I'm going to need to revert this for now.

This was auto-backported to 7.x and 7.15, did you revert it from there as well?

Sorry, missed this, but yes. Thanks for checking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Deprecated - use backport:version if exact versions are needed release_note:skip Skip the PR/issue when compiling release notes reverted v7.15.0 v7.16.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants