Skip to content

Commit

Permalink
chore: update to eslint v9
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed May 1, 2024
1 parent d880b1e commit 3c64544
Show file tree
Hide file tree
Showing 14 changed files with 394 additions and 1,133 deletions.
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

6 changes: 0 additions & 6 deletions .eslintrc

This file was deleted.

15 changes: 15 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import unjs from "eslint-config-unjs";

export default unjs({
ignores: [
// ignore paths
],
rules: {
// rule overrides
},
markdown: {
rules: {
// markdown rule overrides
},
},
});
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"scripts": {
"build": "unbuild",
"dev": "vitest",
"lint": "eslint --ext .ts,.js src test && prettier -c src test",
"lint:fix": "eslint --ext .ts,.js src test --fix && prettier -w src test",
"lint": "eslint src test && prettier -c src test",
"lint:fix": "eslint src test --fix && prettier -w src test",
"release": "pnpm test && pnpm build && changelogen --release && npm publish && git push --follow-tags",
"test": "pnpm lint && pnpm test:types && vitest run",
"test:types": "tsc --noEmit"
Expand All @@ -36,8 +36,8 @@
"@types/node": "^20.12.7",
"@vitest/coverage-v8": "^1.5.3",
"changelogen": "^0.5.5",
"eslint": "^8.57.0",
"eslint-config-unjs": "^0.2.1",
"eslint": "^9.1.1",
"eslint-config-unjs": "0.3.0-rc.7",
"import-meta-resolve": "^4.1.0",
"jiti": "^1.21.0",
"prettier": "^3.2.5",
Expand Down
1,463 changes: 358 additions & 1,105 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/analyze.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { tokenizer } from "acorn";
import { matchAll, clearImports, getImportNames } from "./_utils";
import { resolvePath, ResolveOptions } from "./resolve";
import { resolvePath, type ResolveOptions } from "./resolve";
import { loadURL } from "./utils";

/**
Expand Down Expand Up @@ -453,7 +453,7 @@ export function findExports(code: string): ESMExport[] {
});

// Merge and normalize exports
// eslint-disable-next-line unicorn/no-array-push-push

const exports: ESMExport[] = normalizeExports([
...declaredExports,
...namedExports,
Expand Down Expand Up @@ -652,7 +652,9 @@ function _filterStatement<T extends TokenLocation>(
function _tryGetLocations(code: string, label: string) {
try {
return _getLocations(code, label);
} catch {}
} catch {
// Ignore error
}
}

function _getLocations(code: string, label: string) {
Expand Down
6 changes: 4 additions & 2 deletions src/cjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface CommonjsContext {
*/
__dirname: string;
// TODO!
// eslint-disable-next-line no-undef

/**
* A function to require modules as in CommonJS.
*/
Expand Down Expand Up @@ -81,7 +81,9 @@ export function interopDefault(
},
});
}
} catch {}
} catch {
// Ignore error
}
}
return defaultValue;
}
2 changes: 1 addition & 1 deletion test/exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe("findExports", () => {
specifier: "./other",
name: "foo",
},
// eslint-disable-next-line no-template-curly-in-string

"const a = `<div${JSON.stringify({ class: 42 })}>`;\nexport default true;":
{ type: "default", name: "default", names: ["default"] },
"export const enum foo { a = 'xx' }": {
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/eval-err.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-nocheck
// eslint-disable-next-line require-await

async function test() {
throw new Error("Something went wrong in eval-err module!");
}
Expand Down
4 changes: 2 additions & 2 deletions test/fixture/eval.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ console.log(
),
);

await loadModule("./eval-err.mjs", { url: import.meta.url }).catch((e) =>
console.error(e),
await loadModule("./eval-err.mjs", { url: import.meta.url }).catch((error) =>
console.error(error),
);
1 change: 0 additions & 1 deletion test/fixture/imports/js-cjs/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line unicorn/prefer-module
module.exports = "js-cjs";

console.log(import("node:fs"));
5 changes: 3 additions & 2 deletions test/fixture/imports/mixed/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable unicorn/prefer-module */
export const isCrtAvailable = () => {
try {
if (
Expand All @@ -8,5 +7,7 @@ export const isCrtAvailable = () => {
) {
return ["md/crt-avail"];
}
} catch {}
} catch {
// Ignore error
}
};
2 changes: 1 addition & 1 deletion test/fixture/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function reverse(str) {
return str.split("").reverse().join("");
return [...str].reverse().join("");
}
1 change: 0 additions & 1 deletion test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ describe("parseNodeModulePath", () => {
});

describe("lookupNodeModuleSubpath", () => {
// eslint-disable-next-line unicorn/consistent-function-scoping
const r = (p: string) => new URL(p, import.meta.url).toString();

const tests = [
Expand Down

0 comments on commit 3c64544

Please sign in to comment.