-
-
Notifications
You must be signed in to change notification settings - Fork 11
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: Add migrate-config CLI tool #26
Conversation
Not entirely sure why JSR thinks the directory is dirty. 🤔 |
Perhaps we could temporarily add rewrite/packages/compat/package.json Line 28 in 5f0d2e2
|
Seems to be a problem with changing file permissions
|
I think what happens here is that
What might help is to do this:
After this, you should see new permissions:
Then, commit the file & push. |
Ah, thanks for digging into that. 🙏 Looks like it worked! |
It looks like the build script crashes because it assumes that every package that starts with |
"publishConfig": { | ||
"access": "public" | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its public by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Fixed the build script. 👍 |
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Great feedback, thanks! Updated everything and even cleaned up some unnecessary objects that were being output. |
? config.ignorePatterns | ||
: [config.ignorePatterns]; | ||
const ignorePatternsArray = b.arrayExpression( | ||
ignorePatterns.map(pattern => b.literal(gitignoreToMinimatch(pattern))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some cases where gitignoreToMinimatch
doesn't return patterns that are in the current flat config implementation of global ignores equivalent to eslintrc patterns.
For example:
eslintrc (.gitignore) | flat config equivalent | gitIgnoreToMinimatch |
---|---|---|
*/a.js |
*/a.js |
**/*/a.js |
dir/** |
dir/**/* |
dir/** |
dir/ |
**/dir/ |
**/dir/** |
Here's a function that I believe should correctly convert patterns:
function convert(pattern) {
const isNegated = pattern.startsWith("!");
const negatedPrefix = isNegated ? "!" : "";
const patternToTest = (isNegated ? pattern.slice(1) : pattern).trimEnd();
// special cases
if (["", "**", "/**", "**/"].includes(patternToTest)) {
return `${negatedPrefix}${patternToTest}`;
}
const firstIndexOfSlash = patternToTest.indexOf("/");
const matchEverywherePrefix =
firstIndexOfSlash < 0 || firstIndexOfSlash === patternToTest.length - 1
? "**/"
: "";
const patternWithoutLeadingSlash =
firstIndexOfSlash === 0
? patternToTest.slice(1)
: patternToTest;
const matchInsideSuffix =
patternToTest.endsWith("/**")
? "/*"
: "";
return `${negatedPrefix}${matchEverywherePrefix}${patternWithoutLeadingSlash}${matchInsideSuffix}`;
}
Tests
const assert = require("node:assert");
describe("convert", () => {
const test = {
"**": "**",
"/**": "/**",
"**/": "**/",
"/**/": "**/",
"": "",
" ": "",
" ": "",
"a/b ": "a/b",
"a/b ": "a/b",
"*": "**/*",
"*/": "**/*/",
"/*": "*",
"/*/": "*/",
"a": "**/a",
"a/": "**/a/",
"/a": "a",
"/a/": "a/",
"**/*": "**/*",
"*/a": "*/a",
"*/a/": "*/a/",
"/*/a": "*/a",
"/*/a/": "*/a/",
"a/b": "a/b",
"a/b/": "a/b/",
"/a/b": "a/b",
"/a/b/": "a/b/",
"a/**/b": "a/**/b",
"a/**/b/": "a/**/b/",
"/a/**/b": "a/**/b",
"/a/**/b/": "a/**/b/",
"a/b/**": "a/b/**/*",
"/a/b/**": "a/b/**/*",
"/a/b/**": "a/b/**/*",
"a/b/**/": "a/b/**/",
"/a/b/**/": "a/b/**/",
"*/a.js": "*/a.js",
"dir/**": "dir/**/*",
"dir/": "**/dir/",
"dir/**/": "dir/**/"
};
for (const [oldPattern, newPattern] of Object.entries(test)) {
test[`!${oldPattern}`] = `!${newPattern}`;
}
for (const [oldPattern, newPattern] of Object.entries(test)) {
it(`for "${oldPattern}" should return ${newPattern}`, () => {
assert.strictEqual(convert(oldPattern), newPattern);
});
}
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying this is a bug in gitignoreToMinimatch
? Or that we are doing something unique?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying this is a bug in
gitignoreToMinimatch
?
Depends on what it is designed for. In earlier iterations of config-array, global ignore patterns were matching only files, and gitignoreToMinimatch
indeed translates gitignore patterns that match files and directories to minimatch patterns that are intended to match files (though such translation can't guarantee correctness). But now config-array global ignore patterns can match directories too.
Or that we are doing something unique?
What we now have in config-array is like a more powerful gitignore. Minimatch patterns provide more features than gitignore patterns (for example, this would be much more difficult to achieve with gitignore patterns), and except for the differences in individual patterns, principles are the same as in gitignore:
- Patterns can match both files and directories.
- Files in ignored directories are considered ignored.
- Unignoring works the same.
So it's easy to switch from gitignore reasoning to config-array ignore reasoning because it's generally the same + enhanced syntax.
There are only two notable differences in semantics, which the above code addresses (and users should be aware of):
- In config-array, patterns are always relative to the root, whereas in gitignore, patterns that don't have a slash at the beginning or in the middle can match at any level.
- In config-array,
foo/**
matches directoryfoo/
in addition to everything inside (foo/**
should not matchfoo/
isaacs/minimatch#179), whereas in gitignore it doesn't match directoryfoo/
, only everything inside.
There would be more work to achieve 100% correctness, e.g., some literal characters in gitignore patterns can have syntactic meaning in minimatch patterns, but those are very edge cases I believe.
Updated the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
This pull request adds a new package,
@eslint/migrate-config
, that is just a CLI tool designed to be run vianpx
.This is different than other packages in a couple ways:
src
.Note: This is intended to be a first-pass of this tool to get people started. I'm not intending for this to be a perfect solution, but I've tested the output on a bunch of open source projects and found that it typically gets the config around 90% of the way there.