Skip to content

Commit

Permalink
Add a fix option
Browse files Browse the repository at this point in the history
  • Loading branch information
pashak09 committed Oct 19, 2023
1 parent 91bc6ff commit 84b7e3c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-require-node-import-prefix",
"version": "0.0.1",
"version": "0.0.2",
"author": "pashak09",
"description": "A rule that enforces to use the `node:` prefix for nodejs built-ins",
"license": "MIT",
Expand Down
2 changes: 2 additions & 0 deletions src/eslint-plugin-require-node-import-prefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export const rule: Rule.RuleModule = {
context.report({
node: source,
messageId: 'invalidBuiltInImport',
fix: (fixer: Rule.RuleFixer): Rule.Fix =>
fixer.replaceText(source, `'node:${moduleName}'`),
data: {
moduleName,
},
Expand Down
2 changes: 2 additions & 0 deletions tests/eslint-plugin-require-node-import-prefix.Spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ruleTester.run('no-empty-import-prefix', rule, {
invalid: [
{
code: "import { builtinModules } from 'module';",
output: "import { builtinModules } from 'node:module';",
errors: [
{
messageId: 'invalidBuiltInImport',
Expand All @@ -33,6 +34,7 @@ ruleTester.run('no-empty-import-prefix', rule, {
},
{
code: "import fs from 'fs'",
output: "import fs from 'node:fs'",
errors: [
{
messageId: 'invalidBuiltInImport',
Expand Down

0 comments on commit 84b7e3c

Please sign in to comment.