-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
Accept more types of eslint presets #96
Conversation
Codecov Report
|
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.
Thanks for the pull request!
packages/mrm-task-eslint/index.js
Outdated
const match = presetName.match(presetNameRegex); | ||
|
||
if (!match) { | ||
throw new Error('Invalid preset name'); |
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.
Let's make it more clear for the user:
throw new Error('Invalid preset name'); | |
throw new Error(`Invalid preset name is passed to the eslint task: ${presetName}`); |
packages/mrm-task-eslint/index.js
Outdated
const scope = match[1] || ''; | ||
let configName = match[2]; | ||
|
||
if (!scope && !configName.startsWith(prefix)) { | ||
configName = `${prefix}-${configName}`; | ||
} else if (scope && !configName) { | ||
configName = prefix; | ||
} | ||
|
||
const packageName = `${scope ? `${scope}/` : ''}${configName}`; | ||
|
||
return packageName; | ||
}; |
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.
Let's extract this piece to a function to avoid reassignment:
const [, scope = '', configNameRaw] = match;
// ...
const getConfigName = (configName, scope, prefix) => {
if (!scope && !configName.startsWith(prefix)) {
return `${prefix}-${configName}`;
} else if (scope && !configName) {
return prefix;
} else {
return configName;
}
}
packages/mrm-task-eslint/index.js
Outdated
const presetPackage = normalizePresetPackageName(eslintPreset); | ||
packages.push(presetPackage); |
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.
A variable doesn't improve readability here:
const presetPackage = normalizePresetPackageName(eslintPreset); | |
packages.push(presetPackage); | |
packages.push(normalizePresetPackageName(eslintPreset)); |
Codecov Report
|
Thanks, merging! 🦄 |
This change expands the set of eslint preset names accepted by the eslint task to be closer to what is accepted by eslint for the
extends
configuration option including scoped packages and intra-package configs (e.g.eslint-config-airbnb/whitespace
). This change does not include support for presets specified by a file path.It's worth noting that the
@eslint/eslintrc
package exports anormalizePackageName
function, but there are a couple issues with that: