-
Notifications
You must be signed in to change notification settings - Fork 101
Added quick utility script for making a new rule #1089
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8508874
Added quick utility script for making a new rule
JoshuaKGoldberg 526f7f8
Simple import sort: will pull into separate branch
JoshuaKGoldberg 9bce424
Enabled eslint-plugin-simple-import-sort internally
JoshuaKGoldberg a3c592f
Added eslint-plugin-simple-import-sort
JoshuaKGoldberg 00f0906
Merge branch 'simple-import-sort'
5f9e490
Reset package-lock.json
131070d
Merge branch 'simple-import-script'
cf3800c
Added back simple-import-sort
d5e5109
Reset .eslintrc.js
a4a3687
Remove test bed files
59af008
Merge branch 'main'
JoshuaKGoldberg c185030
Also add to ruleConverters.ts, alphabetically
JoshuaKGoldberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const { Command } = require("commander"); | ||
const { promises: fs } = require("fs"); | ||
const { upperFirst, camelCase } = require("lodash"); | ||
|
||
(async () => { | ||
const command = new Command() | ||
.option("--eslint [eslint]", "name of the original ESLint rule") | ||
.option("--tslint [tslint]", "name of the original TSLint rule"); | ||
|
||
const args = command.parse(process.argv).opts(); | ||
|
||
for (const arg of ["eslint", "tslint"]) { | ||
if (!args[arg]) { | ||
throw new Error(`Missing --${arg} option.`); | ||
} | ||
} | ||
|
||
const tslintPascalCase = upperFirst(camelCase(args.tslint)); | ||
const plugins = args.eslint.includes("/") | ||
? ` | ||
plugins: ["${args.eslint.split("/")[0]}"],` | ||
: ""; | ||
|
||
await fs.writeFile( | ||
`./src/converters/lintConfigs/rules/ruleConverters/${args.tslint}.ts`, | ||
` | ||
import { RuleConverter } from "../ruleConverter"; | ||
|
||
export const convert${tslintPascalCase}: RuleConverter = () => { | ||
return {${plugins} | ||
rules: [ | ||
{ | ||
ruleName: "${args.eslint}", | ||
}, | ||
], | ||
}; | ||
}; | ||
`.trimLeft(), | ||
); | ||
|
||
await fs.writeFile( | ||
`./src/converters/lintConfigs/rules/ruleConverters/tests/${args.tslint}.test.ts`, | ||
` | ||
import { convert${tslintPascalCase} } from "../${args.tslint}"; | ||
|
||
describe(convert${tslintPascalCase}, () => { | ||
test("conversion without arguments", () => { | ||
const result = convert${tslintPascalCase}({ | ||
ruleArguments: [], | ||
}); | ||
|
||
expect(result).toEqual({${plugins.replace("\n", "\n ")} | ||
rules: [ | ||
{ | ||
ruleName: "${args.eslint}", | ||
}, | ||
], | ||
}); | ||
}); | ||
}); | ||
`.trimLeft(), | ||
); | ||
})(); | ||
JoshuaKGoldberg marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.