Skip to content

Commit

Permalink
Chore: lint test files (#18)
Browse files Browse the repository at this point in the history
* Chore: lint test files

* increase mocha timeout for copying fixtures

* fix the timeout fix

* upgrade dev dependencies

* update eslint and eslint-plugin-jsdoc

* fix new files
  • Loading branch information
mdjermanovic committed Feb 28, 2021
1 parent 5ade86b commit 0b2f80d
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 88 deletions.
20 changes: 8 additions & 12 deletions .eslintignore
@@ -1,12 +1,8 @@
/build/**
/coverage/**
/docs/**
/jsdoc/**
/templates/**
/tests/bench/**
/tests/fixtures/**
/tests/performance/**
/tmp/**
/tools/internal-rules/node_modules/**
test.js
!.eslintrc.js
/node_modules/
/tests/fixtures/

/coverage/
/docs/
/jsdoc/


6 changes: 0 additions & 6 deletions .eslintrc.js
Expand Up @@ -19,12 +19,6 @@ module.exports = {
}
},

// TODO: remove when linting problems gets fixed
ignorePatterns: ["/tests/", "/conf/eslint-all.js"],
rules: {
"class-methods-use-this": "off"
},

overrides: [
{
files: ["tests/**/*"],
Expand Down
2 changes: 2 additions & 0 deletions lib/shared/config-validator.js
Expand Up @@ -5,6 +5,8 @@

"use strict";

/* eslint class-methods-use-this: "off" */

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
Expand Down
9 changes: 5 additions & 4 deletions package.json
Expand Up @@ -12,7 +12,8 @@
"access": "public"
},
"scripts": {
"lint": "eslint .",
"lint": "eslint . --report-unused-disable-directives",
"fix": "npm run lint -- --fix",
"test": "mocha -R progress -c 'tests/lib/**/*.js'",
"generate-release": "eslint-generate-release",
"generate-alpharelease": "eslint-generate-prerelease alpha",
Expand All @@ -34,9 +35,9 @@
"homepage": "https://github.com/eslint/eslintrc#readme",
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^7.7.0",
"eslint-config-eslint": "^6.0.0",
"eslint-plugin-jsdoc": "^22.1.0",
"eslint": "^7.21.0",
"eslint-config-eslint": "^7.0.0",
"eslint-plugin-jsdoc": "^32.2.0",
"eslint-plugin-node": "^11.1.0",
"eslint-release": "^3.1.2",
"fs-teardown": "^0.1.0",
Expand Down
53 changes: 34 additions & 19 deletions tests/lib/cascading-config-array-factory.js
Expand Up @@ -18,7 +18,6 @@ const systemTempDir = require("temp-dir");

const {
Legacy: {
ConfigArray,
ConfigArrayFactory,
CascadingConfigArrayFactory,
ExtractedConfig
Expand Down Expand Up @@ -50,7 +49,6 @@ describe("CascadingConfigArrayFactory", () => {
describe("with three directories ('lib', 'lib/nested', 'test') that contains 'one.js' and 'two.js'", () => {
const root = path.join(systemTempDir, "eslint/cli-engine/cascading-config-array-factory");
const files = {
/* eslint-disable quote-props */
"lib/nested/one.js": "",
"lib/nested/two.js": "",
"lib/nested/parser.js": "",
Expand All @@ -67,7 +65,6 @@ describe("CascadingConfigArrayFactory", () => {
"no-unused-vars": "error"
}
})
/* eslint-enable quote-props */
};

/** @type {CascadingConfigArrayFactory} */
Expand All @@ -76,7 +73,7 @@ describe("CascadingConfigArrayFactory", () => {
let prepare, cleanup, getPath;

before(async () => {
({ prepare, cleanup, getPath} = createCustomTeardown({
({ prepare, cleanup, getPath } = createCustomTeardown({
cwd: root,
files
}));
Expand Down Expand Up @@ -168,7 +165,7 @@ describe("CascadingConfigArrayFactory", () => {
describe("when '~/.eslintrc.json' exists and CWD is `~/`", () => {

let prepare, cleanup, getPath;

beforeEach(async () => {

({ prepare, cleanup, getPath } = createCustomTeardown({
Expand All @@ -189,7 +186,7 @@ describe("CascadingConfigArrayFactory", () => {

await prepare();
cwd = getPath();

factory = new CascadingConfigArrayFactory({ cwd });
});

Expand Down Expand Up @@ -356,12 +353,12 @@ describe("CascadingConfigArrayFactory", () => {

let prepare, cleanup, getPath;
let configFilePath;

beforeEach(async () => {

cwd = path.join(homeDir, "../another");
configFilePath = `../${uniqueHomeDirName}/.eslintrc.json`;

({ prepare, cleanup, getPath } = createCustomTeardown({
cwd,
files: {
Expand All @@ -377,12 +374,12 @@ describe("CascadingConfigArrayFactory", () => {
"not-exist/test.js": ""
}
}));


await prepare();
factory = new CascadingConfigArrayFactory({ cwd: getPath() });
});

afterEach(async () => {
await cleanup();
sh.rm("-rf", homeDir);
Expand Down Expand Up @@ -453,9 +450,9 @@ describe("CascadingConfigArrayFactory", () => {
});

describe("when '~/.eslintrc.json' doesn't exist and CWD is `~/subdir`", () => {

let prepare, cleanup, getPath;

beforeEach(async () => {
cwd = path.join(homeDir, "subdir");

Expand Down Expand Up @@ -493,10 +490,10 @@ describe("CascadingConfigArrayFactory", () => {

describe("when '~/.eslintrc.json' doesn't exist and CWD is `~/../another`", () => {
let prepare, cleanup, getPath;

beforeEach(async () => {
cwd = path.join(homeDir, "../another");

({ prepare, cleanup, getPath } = createCustomTeardown({
cwd,
files: {
Expand Down Expand Up @@ -534,11 +531,19 @@ describe("CascadingConfigArrayFactory", () => {
// hack to avoid needing to hand-rewrite file-structure.json
const DIRECTORY_CONFIG_HIERARCHY = (() => {
const rawData = require("../fixtures/config-hierarchy/file-structure.json");

// key is path, value is file content (string)
const flattened = {};

/** Recursively joins path segments and populates `flattened` object
* @param {Object} object key is path segment, value is file content (string) or another object of the same kind
* @param {string} prefix parent directory
* @returns {void}
*/
function flatten(object, prefix = "") {
for (const key of Object.keys(object)) {
const newPrefix = path.join(prefix, key);

if (typeof object[key] === "string") {
flattened[newPrefix] = object[key];
} else {
Expand Down Expand Up @@ -608,15 +613,24 @@ describe("CascadingConfigArrayFactory", () => {
function getConfig(factory, filePath = "a.js") {
const { cwd } = factory;
const absolutePath = path.resolve(cwd, filePath);

return factory
.getConfigArrayForFile(absolutePath)
.extractConfig(absolutePath)
.toCompatibleObjectAsConfigFileContent();
}

// copy into clean area so as not to get "infected" by this project's .eslintrc files
before(() => {
before(function() {

/*
* GitHub Actions Windows and macOS runners occasionally exhibit
* extremely slow filesystem operations, during which copying fixtures
* exceeds the default test timeout, so raise it just for this hook.
* Mocha uses `this` to set timeouts on an individual hook level.
*/
this.timeout(60 * 1000); // eslint-disable-line no-invalid-this

fixtureDir = `${systemTempDir}/eslint/fixtures`;
sh.mkdir("-p", fixtureDir);
sh.cp("-r", "./tests/fixtures/config-hierarchy", fixtureDir);
Expand Down Expand Up @@ -1895,6 +1909,7 @@ describe("CascadingConfigArrayFactory", () => {
});

describe("bug fixes", () => {

/*
* Clearing cache would previously error on 'createBaseConfigArray()' call
* with 'TypeError: loadRules is not a function'
Expand All @@ -1905,7 +1920,7 @@ describe("CascadingConfigArrayFactory", () => {
rulePaths: ["./rules"],
loadRules() {
return [];
},
}
});

factory.clearCache();
Expand Down

0 comments on commit 0b2f80d

Please sign in to comment.