Skip to content

Commit

Permalink
chore: switch to eslint flat config
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Aug 30, 2023
1 parent 38d293a commit 9230df0
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 38 deletions.
24 changes: 0 additions & 24 deletions .eslintrc.cjs

This file was deleted.

30 changes: 30 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import eslintConfigESLint from "eslint-config-eslint";
import globals from "globals";

export default [
{
ignores: [
"coverage/",
"tests/fixtures/"
]
},
...eslintConfigESLint,
{
settings: {
jsdoc: {
preferredTypes: {
Object: "object",
"object<>": "Object"
}
}
}
},
{
files: ["tests/**"],
languageOptions: {
globals: {
...globals.mocha
}
}
}
];
2 changes: 0 additions & 2 deletions lib/init/config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ function writeJSONConfigFile(config, filePath) {
async function writeYAMLConfigFile(config, filePath) {
debug(`Writing YAML config file: ${filePath}`);

// lazy load YAML to improve performance when not used
// eslint-disable-next-line node/no-unsupported-features/es-syntax
const yaml = await import("js-yaml");

const content = yaml.dump(config, { sortKeys: true });
Expand Down
4 changes: 3 additions & 1 deletion lib/init/config-initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ function askInstallModules(modules) {
/**
* Ask use a few questions on command prompt
* @returns {Promise<void>} The promise with the result of the prompt
* @throws {Error} If `package.json` file doesn't exist.
*/
function promptUser() {
const packageJsonExists = npmUtils.checkPackageJson();
Expand Down Expand Up @@ -598,7 +599,8 @@ function promptUser() {
}

/* istanbul ignore next */
/** an wrapper for promptUser
/**
* an wrapper for promptUser
* @returns {void}
*/
function initializeConfig() {
Expand Down
3 changes: 1 addition & 2 deletions lib/init/npm-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ function findPackageJson(startDir) {
function installSyncSaveDev(packages, packageManager = "npm") {
const packageList = Array.isArray(packages) ? packages : [packages];
const installCmd = packageManager === "yarn" ? "add" : "install";
const installProcess = spawn.sync(packageManager, [installCmd, "-D"].concat(packageList),
{ stdio: "inherit" });
const installProcess = spawn.sync(packageManager, [installCmd, "-D"].concat(packageList), { stdio: "inherit" });
const error = installProcess.error;

if (error && error.code === "ENOENT") {
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"access": "public"
},
"scripts": {
"lint": "eslint .",
"lint": "eslint . --report-unused-disable-directives",
"release:generate:latest": "eslint-generate-release",
"release:generate:alpha": "eslint-generate-prerelease alpha",
"release:generate:beta": "eslint-generate-prerelease beta",
Expand All @@ -55,13 +55,12 @@
"devDependencies": {
"c8": "^7.10.0",
"chai": "^4.3.4",
"eslint": "^8.2.0",
"eslint-config-eslint": "^7.0.0",
"eslint-plugin-jsdoc": "^37.0.3",
"eslint-plugin-node": "^11.1.0",
"eslint": "^8.48.0",
"eslint-config-eslint": "^9.0.0",
"eslint-release": "^3.2.0",
"esmock": "^2.2.3",
"espree": "^9.0.0",
"globals": "^13.21.0",
"lint-staged": "^12.1.2",
"memfs": "^3.4.0",
"mocha": "^9.1.3",
Expand Down
6 changes: 3 additions & 3 deletions tests/init/config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe("ConfigFile", () => {

it(`should write a file through fs when a ${fileType} path is passed`, async () => {
const fakeFS = {
writeFileSync: () => {}
writeFileSync() {}
};

sinon.mock(fakeFS).expects("writeFileSync").withExactArgs(
Expand All @@ -84,7 +84,7 @@ describe("ConfigFile", () => {

it("should include a newline character at EOF", async () => {
const fakeFS = {
writeFileSync: () => {}
writeFileSync() {}
};

sinon.mock(fakeFS).expects("writeFileSync").withExactArgs(
Expand All @@ -103,7 +103,7 @@ describe("ConfigFile", () => {

it("should run 'eslint --fix' to make sure js config files match linting rules", async () => {
const fakeFS = {
writeFileSync: () => {}
writeFileSync() {}
};

const singleQuoteConfig = {
Expand Down
2 changes: 1 addition & 1 deletion tests/init/config-initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe("configInitializer", () => {

// copy into clean area so as not to get "infected" by this project's .eslintrc files
before(() => {
const __filename = fileURLToPath(import.meta.url); // eslint-disable-line no-underscore-dangle
const __filename = fileURLToPath(import.meta.url); // eslint-disable-line no-underscore-dangle -- Conventional

fixtureDir = path.join(__filename, "../../../tmp/eslint/fixtures/config-initializer");
localInstalledEslintDir = path.join(fixtureDir, "./node_modules/eslint");
Expand Down

0 comments on commit 9230df0

Please sign in to comment.