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: relative cache support #106

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 65 additions & 0 deletions designs/2023-relative-cache/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
- Repo: eslint/eslint
- Start Date: 2023-02-14
- RFC PR: <https://github.com/eslint/rfcs/pull/106>
- Authors: Christian Schulz (@cschulz)

# Relative cache location strategy

## Summary

To be able to share the created eslint cache between different systems f.e. local machine and CI, there is a need for a relative path stored in the cache.

## Motivation

The overall motivation for doing this is performance during the eslint process.

Most people are running eslint on local developer machine and additional on the CI workers.
In high changing repositories there are several pull requests at the same time changing different files requiring linting all the time.
This is a time consuming process depending on the enabled rules like type checking rules.

If the CI worker is able to cache its last run, it can just pick this cache up and use it.
Also developers can reuse this cache or commit it as part of a repository for the CI.

## Detailed Design

The LintResultCache takes a file path as parameter to find or store a file cache entry.
Copy link
Member

Choose a reason for hiding this comment

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

We need more details in this section. It should be written in such a way that someone else would be able to implement it. Please reference filenames, classes, etc., and what would have to change so we can get an idea of the implementation complexity. We'd like your recommendation for the best way to implement your suggestion. As-is, there's not enough detail here to comment on.

Copy link
Author

Choose a reason for hiding this comment

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

@nzakas Can you help me out here? I am not so familar with the code to answer such questions in this detail level.

Copy link
Member

Choose a reason for hiding this comment

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

@CSchulz I completely understand. Part of the RFC process is to have you get familiar with the code to see how plausible it is to implement (otherwise, we will have to do that for every RFC and there's just not enough time for that).

For this change, start by looking in lib/eslint/flat-eslint.js.


One approach would be to truncate the given absolute path of the file by the path of the cache location.

Another approach to get a relative path is to use the parent eslint config file if we are thinking about config hierarchies.

The configuration should be done by CLI flags like the cache strategy option itself.

## Documentation

Add the new CLI flag to the CLI documentation.

## Drawbacks

No.

## Backwards Compatibility Analysis
CSchulz marked this conversation as resolved.
Show resolved Hide resolved

Existing caches needs to be depleted, because there is no cache version entry existing.

Another way would be to ignore existing absolute paths and write the new relative path if enabled.

## Alternatives

A CLI tool which translates the existing cache to the current folder structure.

## Open Questions

No.

## Help Needed

TBD

## Frequently Asked Questions

TBD

## Related Discussions

[Change Request: Eslintcache relative #16493](https://github.com/eslint/eslint/issues/16493)