Skip to content

Commit

Permalink
fix: fail node/no-missing-import rule on TS files (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
koba04 authored and shisama committed Dec 26, 2019
1 parent f76cf20 commit cac1f84
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/node.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module.exports = {
extends: ["plugin:node/recommended"],
settings: {
node: {
// https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-missing-import.md#tryextensions
tryExtensions: [".js", ".json", ".node", ".ts", ".jsx", ".tsx"]
}
},
rules: {
"no-console": "off"
}
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/node-typescript/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { sum } from "./sum2";
sum();
3 changes: 3 additions & 0 deletions test/fixtures/node-typescript/ok.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// prettier-ignore
import { sum } from "./sum";
sum();
3 changes: 3 additions & 0 deletions test/fixtures/node-typescript/sum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const sum = () => {
return 10;
};
1 change: 0 additions & 1 deletion test/lib/runLintWithFixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const runLintWithFixtures = (type, configFile = `lib/${type}.js`) => {
const targetDir = path.resolve(__dirname, "..", "fixtures", type);
const lintResult = cli.executeOnFiles([targetDir]);
// console.log(JSON.stringify(lintResult, null, 2));

return lintResult.results.reduce((results, { filePath, messages }) => {
// strip path
const fileName = filePath.replace(`${targetDir}/`, "");
Expand Down
19 changes: 19 additions & 0 deletions test/node-typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const assert = require("assert");
const runLintWithFixtures = require("./lib/runLintWithFixtures");

describe("node-typescript", () => {
it("should get expected errors and warninigs", () => {
// We use react presets in order to support ES2017 syntax
const result = runLintWithFixtures(
"node-typescript",
"presets/node-typescript-prettier.js"
);
assert.deepStrictEqual(result, {
"ok.ts": {},
"sum.ts": {},
"error.ts": {
errors: ["node/no-missing-import"]
}
});
});
});

0 comments on commit cac1f84

Please sign in to comment.