-
Notifications
You must be signed in to change notification settings - Fork 100
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
Added Node API #732
Added Node API #732
Conversation
This should now be available on npm to try out locally via https://www.npmjs.com/package/tslint-to-eslint-config/v/2.0.0-beta0. 🚀 cc @JamesHenry |
Thanks so much for publishing that @JoshuaKGoldberg! After some digging I was able to get to the bottom of why my conversion was not behaving the same as when using the CLI (the rule severities and configs were not being reflected if you remember). It is because Full is the result of running So I have managed to get it fully working after extracting some more parts of the library into my code. I believe, however, I can avoid the need for that if you just expose to me the Here is an abridged version of my full usage of the library: const reportedConfiguration = await findReportedConfiguration(
childProcessExec,
'npx tslint --print-config',
pathToTslintJson
);
// ... error handling here...
const originalConfigurations = {
tslint: {
full: reportedConfiguration,
raw: rawTslintJson,
},
};
const summarizedConfiguration = await createESLintConfiguration(
originalConfigurations
);
const convertedESLintConfig = joinConfigConversionResults(
summarizedConfiguration,
originalConfigurations
); Let me know if you have any questions! |
Thanks for the updates! Please could you publish another beta whenever you get chance? Not urgent! |
Super, published |
This is looking really good! I haven't yet tackled the disable comment conversion logic, but for configs I think we are basically there. You can see my full usage of the API below for reference. I have the following main request/callout as things stand: With this usage below I am still ending up with an empty
import type { Linter as ESLintLinter } from 'eslint';
import {
createESLintConfiguration,
findReportedConfiguration,
joinConfigConversionResults,
} from 'tslint-to-eslint-config';
type TSLintRuleSeverity = 'warning' | 'error' | 'off';
type TSLintRuleOptions = {
ruleArguments: any[];
ruleName: string;
ruleSeverity: TSLintRuleSeverity;
};
export async function convertToESLintConfig(
pathToTslintJson: string,
tslintJson: Record<string, unknown>,
): Promise<{
convertedESLintConfig: ESLintLinter.Config;
unconvertedTSLintRules: TSLintRuleOptions[];
}> {
const reportedConfiguration = await findReportedConfiguration(
'npx tslint --print-config',
pathToTslintJson,
);
if (reportedConfiguration instanceof Error) {
if (
reportedConfiguration.message.includes('unknown option `--print-config')
) {
throw new Error(
'\nError: TSLint v5.18 required in order to run this schematic. Please update your version and try again.\n',
);
}
throw new Error(`Unexpected error: ${reportedConfiguration.message}`);
}
const originalConfigurations = {
tslint: {
full: reportedConfiguration,
raw: tslintJson,
},
};
const summarizedConfiguration = await createESLintConfiguration(
originalConfigurations,
);
const convertedESLintConfig = joinConfigConversionResults(
summarizedConfiguration,
originalConfigurations,
) as ESLintLinter.Config;
return {
convertedESLintConfig,
unconvertedTSLintRules: summarizedConfiguration.missing,
};
} |
Indeed, we can: the issue, I think, is that
...even though it's not used in this code. I'll switch it to only creating that write stream once, when first needed in calling |
@JamesHenry try the latest beta2? |
beta2 is looking good! |
Informal approvals from @KingDarBoja (over Gitter) and @JamesHenry (by virtue of #173 existing and me presuming), so I'm going to merge this! 🚀 If anybody has further requests on it, please do let me know somewhere and/or file an issue -- I'd like to tackle them before we stable release 2.0.0. |
PR Checklist
status: accepting prs
Overview
Creates a new
convertTSLintConfigStandalone
method that's exported asconvertTSLintConfig
bysrc/index.ts
, along with all thesrc/types
helpers used by its public API. Its usage is explained in a newdocs/API.md
file:This method necessitated making the first half of the existing
convertLintConfig
available on their own, so it's split out into a newcreateESLintConfiguration
method.I also moved all the dependency initialization to its own
src/api/dependencies.md
file so it can be re-used in that standalone method.