Skip to content

Commit

Permalink
fix: eslint-config package reference, improve es-lint build script (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya authored Jan 24, 2020
1 parent de8496d commit 48a6ac4
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 15 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist
fixtures
coverage
__snapshots__
src/generated
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"root": true,
"extends": [
"./packages/eslint-config"
]
Expand Down
23 changes: 15 additions & 8 deletions packages/eslint-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ const path = require("path");
module.exports = {
env: {
browser: true,
mocha: true,
node: true,
},
plugins: [
"@typescript-eslint",
"@typescript-eslint/tslint",
"@blueprintjs/blueprint"
"@blueprintjs/blueprint",
],
extends: [
"plugin:@blueprintjs/blueprint/recommended"
"plugin:@blueprintjs/blueprint/recommended",
],
parser: "@typescript-eslint/parser",
parserOptions: {
Expand All @@ -40,7 +38,16 @@ module.exports = {
rules: {
// run the tslint rules which are not yet converted (run inside eslint)
"@typescript-eslint/tslint/config": ["error", {
"lintFile": path.resolve(__dirname, "./tslint.json")
}]
}
}
"lintFile": path.resolve(__dirname, "./tslint.json"),
}],
},
overrides: [
{
files: ["test/**/*"],
env: {
browser: true,
mocha: true,
},
},
],
};
1 change: 1 addition & 0 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "ESLint configuration for @blueprintjs packages",
"dependencies": {
"@blueprintjs/eslint-plugin-blueprint": "^0.1.0",
"@blueprintjs/tslint-config": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^2.15.0",
"@typescript-eslint/eslint-plugin-tslint": "^2.15.0",
"@typescript-eslint/parser": "^2.15.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/tslint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../tslint-config",
"extends": "@blueprintjs/tslint-config",
"rules": {
"file-header": {
"options": [
Expand Down
37 changes: 31 additions & 6 deletions packages/node-build-scripts/es-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
const path = require("path");
const fs = require("fs");
const { junitReportPath } = require("./utils");
const { spawn, execSync } = require("child_process");
const { execSync, spawn } = require("child_process");
const glob = require("glob");

const IGNORE_FILE_NAME = ".eslintignore";

let format = "codeframe";
let out;
let outputStream = process.stdout;
Expand All @@ -24,18 +26,26 @@ if (process.env.JUNIT_REPORT_PATH != null) {
outputStream = fs.createWriteStream(out, { flags: "w+" });
}

const gitRoot = execSync("git rev-parse --show-toplevel").toString().trim();
const commandLineOptions = ["-c", path.join(gitRoot, "./.eslintrc.json"), "--color", "-f", format];
if (process.argv.includes("--fix")) {
commandLineOptions.push("--fix")
// additional args provided to es-lint script
const additionalArgs = process.argv.filter(a => {
// exclude engine and script name
return ["node", "es-lint"].every(s => path.basename(a) !== s);
});

// by default, ESLint only looks for .eslintignore in the current directory, but it might exist at the project root
const ignoreFilepath = findIgnoreFile();
if (ignoreFilepath !== undefined) {
additionalArgs.push("--ignore-path", ignoreFilepath);
}

const commandLineOptions = ["--color", "-f", format, ...additionalArgs];

// ESLint will fail if provided with no files, so we expand the glob before running it
const fileGlob = "{src,test}/**/*.{ts,tsx}";
const absoluteFileGlob = path.resolve(process.cwd(), fileGlob);
const anyFilesToLint = glob.sync(absoluteFileGlob)
if (anyFilesToLint.length === 0) {
console.log(`Not running ESLint because no files match the glob "${fileGlob}"`)
console.log(`[node-build-scripts] Not running ESLint because no files match the glob "${fileGlob}"`)
process.exit();
}

Expand All @@ -47,3 +57,18 @@ eslint.stderr.pipe(process.stderr);
eslint.on("close", code => {
process.exitCode = code;
});

function findIgnoreFile() {
if (fs.existsSync(path.join(process.cwd(), IGNORE_FILE_NAME))) {
return undefined;
}

const gitRoot = execSync("git rev-parse --show-toplevel").toString().trim();
const rootIgnoreFilepath = path.join(gitRoot, IGNORE_FILE_NAME);
if (fs.existsSync(rootIgnoreFilepath)) {
console.log(`[node-build-scripts] Using ESLint ignore file path ${rootIgnoreFilepath}`)
return rootIgnoreFilepath;
}

return undefined;
}

1 comment on commit 48a6ac4

@blueprint-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix: eslint-config package reference, improve es-lint build script (#3940)

Previews: documentation | landing | table

Please sign in to comment.