-
-
Notifications
You must be signed in to change notification settings - Fork 222
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
TSLint #264
Comments
Option 1 seems to be the most future-proof no? |
Probably, yes. Although I don't think TSLint will move far away from ESLint, the idea behind the project is to work the same but for TypeScript. Here is how option 2 would look like: --- src/special/eslint.js 2018-08-09 13:33:55.000000000 +0100
+++ src/utils/linters.js 2018-08-09 14:08:52.000000000 +0100
@@ -37,51 +37,51 @@
return [obj];
}
-function isEslintConfigAnAbsolutePath(specifier) {
+function isLinterConfigAnAbsolutePath(specifier) {
return path.isAbsolute(specifier);
}
-function isEslintConfigARelativePath(specifier) {
+function isLinterConfigARelativePath(specifier) {
return lodash.startsWith(specifier, './') || lodash.startsWith(specifier, '../');
}
-function isEslintConfigFromAPlugin(specifier) {
+function isLinterConfigFromAPlugin(specifier) {
return lodash.startsWith(specifier, 'plugin:');
}
-function isEslintConfigFromAScopedModule(specifier) {
+function isLinterConfigFromAScopedModule(specifier) {
return lodash.startsWith(specifier, '@');
}
-function isEslintConfigFromAFullyQualifiedModuleName(specifier, prefix) {
+function isLinterConfigFromAFullyQualifiedModuleName(specifier, prefix) {
return lodash.startsWith(specifier, prefix);
}
-function resolvePresetPackage(preset, rootDir) {
+function resolvePresetPackage(flavour, preset, rootDir) {
// inspired from https://github.com/eslint/eslint/blob/5b4a94e26d0ef247fe222dacab5749805d9780dd/lib/config/config-file.js#L347
- if (isEslintConfigAnAbsolutePath(preset)) {
+ if (isLinterConfigAnAbsolutePath(preset)) {
return preset;
}
- if (isEslintConfigARelativePath(preset)) {
+ if (isLinterConfigARelativePath(preset)) {
return path.resolve(rootDir, preset);
}
const { prefix, specifier } = (
- isEslintConfigFromAPlugin(preset)
- ? { prefix: 'eslint-plugin-', specifier: preset.substring(preset.indexOf(':') + 1) }
- : { prefix: 'eslint-config-', specifier: preset }
+ isLinterConfigFromAPlugin(preset)
+ ? { prefix: `${flavour}-plugin-`, specifier: preset.substring(preset.indexOf(':') + 1) }
+ : { prefix: `${flavour}-config-`, specifier: preset }
);
- if (isEslintConfigFromAScopedModule(specifier)) {
+ if (isLinterConfigFromAScopedModule(specifier)) {
const scope = specifier.substring(0, specifier.indexOf('/'));
const module = specifier.substring(specifier.indexOf('/') + 1);
- if (isEslintConfigFromAFullyQualifiedModuleName(module, prefix)) {
+ if (isLinterConfigFromAFullyQualifiedModuleName(module, prefix)) {
return specifier;
}
return `${scope}/${prefix}${module}`;
}
- if (isEslintConfigFromAFullyQualifiedModuleName(specifier, prefix)) {
+ if (isLinterConfigFromAFullyQualifiedModuleName(specifier, prefix)) {
return specifier;
}
return `${prefix}${specifier}`;
@@ -99,13 +99,13 @@
}
}
-function checkConfig(config, rootDir) {
+function checkConfig(flavour, config, rootDir) {
const parser = wrapToArray(config.parser);
- const plugins = wrapToArray(config.plugins).map(plugin => `eslint-plugin-${plugin}`);
+ const plugins = wrapToArray(config.plugins).map(plugin => `${flavour}-plugin-${plugin}`);
const presets = wrapToArray(config.extends)
- .filter(preset => preset !== 'eslint:recommended')
- .map(preset => resolvePresetPackage(preset, rootDir));
+ .filter(preset => preset !== `${flavour}:recommended`)
+ .map(preset => resolvePresetPackage(flavour, preset, rootDir));
const presetPackages = presets
.filter(preset => !path.isAbsolute(preset))
@@ -120,11 +120,12 @@
return lodash.union(parser, plugins, presetPackages, presetDeps);
}
-export default function parseESLint(content, filename, deps, rootDir) {
+export default function parseLinter(flavour, content, filename, deps, rootDir) {
const basename = path.basename(filename);
- if (/^\.eslintrc(\.json|\.js|\.yml|\.yaml)?$/.test(basename)) {
+ const filenameRegex = new RegExp(`^\\.${flavour}rc(\\.json|\\.js|\\.yml|\\.yaml)?$`);
+ if (filenameRegex.test(basename)) {
const config = parse(content);
- return checkConfig(config, rootDir);
+ return checkConfig(flavour, config, rootDir);
}
return []; |
Go for option 2 then, less code we have the better :) |
Here we go 🚀 #266 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey,
I'm adding support for TSLint, and it turns out that the code is basically exactly the same as for ESLint.
How would you prefer this to be done?
src/util/linters.js
and just have a basic call inspecials/*.js
Cheers 🍻
The text was updated successfully, but these errors were encountered: