Skip to content

Commit

Permalink
chore: reconfigure ESLint again, move prettier to monorepo root (#4080)
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya authored Apr 21, 2020
1 parent 70cf5a7 commit f4e58c6
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 146 deletions.
24 changes: 24 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const config = require("./packages/eslint-config");

const xtends = ["./packages/eslint-config"];

// in CI, we don't wan to run eslint-plugin-prettier because it has a ~50% performance penalty.
// instead, we run yarn format-check at the root to ensure prettier formatting
if (!process.env.CI) {
xtends.push("plugin:prettier/recommended");
}

module.exports = {
...config,
root: true,
extends: xtends,
ignorePatterns: [
"node_modules",
"dist",
"lib",
"fixtures",
"coverage",
"__snapshots__",
"generated"
]
};
15 changes: 0 additions & 15 deletions .eslintrc.json

This file was deleted.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"docs-data": "lerna run compile --scope \"@blueprintjs/docs-data\"",
"format": "prettier --write \"./**/*.{ts,tsx}\"",
"format-check": "prettier --check \"./**/*.{ts,tsx}\"",
"lint": "NODE_ENV=test lerna run --parallel lint",
"lint-fix": "NODE_ENV=test lerna run --parallel lint-fix",
"lint": "lerna run --parallel lint",
"lint-fix": "lerna run --parallel lint-fix",
"serve": "http-server site",
"site": "npm-run-all site:clean -p copy:* -s serve",
"site:clean": "git clean -xdfq site/",
Expand All @@ -50,6 +50,8 @@
"chai": "^4.2.0",
"circle-github-bot": "^2.1.0",
"cross-env": "^5.2.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-prettier": "^3.1.3",
"gh-pages": "^2.0.1",
"http-server": "^0.11.1",
"lerna": "^2.11.0",
Expand Down
66 changes: 42 additions & 24 deletions packages/eslint-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,53 @@
*/

const path = require("path");
const tsConfig = require("./ts");

// in CI, we don't wan to run eslint-plugin-prettier because it has a ~50% performance penalty.
// instead, we run yarn format-check at the root to ensure prettier formatting
const isCI = process.env.NODE_ENV === "test";
const prettierConfig = require("../../.prettierrc.json");

const plugins = [...tsConfig.plugins, "@blueprintjs"];
const xtends = ["plugin:@blueprintjs/recommended"];
const rules = {...tsConfig.rules};

if (!isCI) {
plugins.push("prettier");
xtends.push("plugin:prettier/recommended");
rules["prettier/prettier"] = ["error", prettierConfig];
}

/**
* Enable @blueprintjs/eslint-plugin.
* For TS files, configure typescript-eslint, including type-aware lint rules which use the TS program.
*/
module.exports = {
...tsConfig,
plugins,
extends: xtends,
rules,
plugins: ["@blueprintjs"],
extends: ["plugin:@blueprintjs/recommended"],
parserOptions: { ecmaVersion: 2017 },
rules: {
// HACKHACK: this rule impl has too many false positives
"@blueprintjs/classes-constants": "off",
},
overrides: [
...tsConfig.overrides,
{
files: ["test/**/*"],
files: ["*.js"],
env: {
node: true,
es6: true,
},
},
{
files: ["**/*.{ts,tsx}"],
env: {
browser: true,
},
plugins: ["@typescript-eslint", "@typescript-eslint/tslint"],
parser: "@typescript-eslint/parser",
parserOptions: {
sourceType: "module",
project: ["{src,test}/tsconfig.json"],
},
rules: {
// HACKHACK: this rule is buggy when it sees scoped module names
"@blueprintjs/classes-constants": "off",
// run the tslint rules which are not yet converted (run inside eslint)
"@typescript-eslint/tslint/config": [
"error",
{
lintFile: path.resolve(__dirname, "./tslint.json"),
},
],
},
},
{
files: ["test/**/*"],
env: {
browser: true,
mocha: true,
},
},
],
Expand Down
5 changes: 1 addition & 4 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
"@typescript-eslint/eslint-plugin": "^2.29.0",
"@typescript-eslint/eslint-plugin-tslint": "^2.29.0",
"@typescript-eslint/parser": "^2.29.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-prettier": "^3.1.3",
"prettier": "^1.19.1"
"eslint": "^6.8.0"
},
"repository": {
"type": "git",
Expand Down
48 changes: 0 additions & 48 deletions packages/eslint-config/ts.js

This file was deleted.

7 changes: 6 additions & 1 deletion packages/eslint-plugin/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"root": true,
"extends": [
"../eslint-config/ts.js"
"../../.eslintrc.js"
],
"rules": {
"@blueprintjs/classes-constants": "off",
"@blueprintjs/html-components": "off",
"@blueprintjs/icon-components": "off"
},
"ignorePatterns": [
"node_modules",
"dist",
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "lib/index.js",
"scripts": {
"compile": "tsc -p src/",
"lint": "es-lint",
"lint": "run-p lint:es",
"lint:es": "es-lint",
"lint-fix": "es-lint --fix",
"test": "jest",
"test:jest-ci": "jest --ci --runInBand"
Expand Down
16 changes: 5 additions & 11 deletions packages/karma-build-scripts/createKarmaConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const KARMA_SERVER_PORT = 9876;
*/

module.exports = function createKarmaConfig(
/** @type {KarmaOptions} */ { coverage = true, dirname, coverageExcludes, coverageOverrides }
/** @type {KarmaOptions} */ { coverage = true, dirname, coverageExcludes, coverageOverrides },
) {
const packageManifest = require(`${dirname}/package.json`);

Expand Down Expand Up @@ -74,9 +74,9 @@ module.exports = function createKarmaConfig(
},
// define where to save final remapped coverage reports
remapCoverageReporter: {
'text-summary': null,
html: './coverage/html',
cobertura: './coverage/cobertura.xml'
"text-summary": null,
html: "./coverage/html",
cobertura: "./coverage/cobertura.xml",
},
reporters: ["mocha"],
singleRun: true,
Expand All @@ -92,12 +92,7 @@ module.exports = function createKarmaConfig(

// enable JUnit reporter only if env variable is set (such as on Circle)
if (process.env.JUNIT_REPORT_PATH) {
const outputDir = path.join(
__dirname,
"../..",
process.env.JUNIT_REPORT_PATH,
path.basename(dirname),
);
const outputDir = path.join(__dirname, "../..", process.env.JUNIT_REPORT_PATH, path.basename(dirname));
console.info(`Karma report will appear in ${outputDir}`);
// disable mocha reporter on circle for HUGE performance increase
config.reporters = ["dots", "junit"];
Expand All @@ -115,4 +110,3 @@ module.exports = function createKarmaConfig(

return config;
};

2 changes: 1 addition & 1 deletion packages/node-build-scripts/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
*/

module.exports = {
COPYRIGHT_HEADER: "\/*\n * Copyright 2017 Palantir Technologies, Inc. All rights reserved.\n *\/\n",
COPYRIGHT_HEADER: "/*\n * Copyright 2017 Palantir Technologies, Inc. All rights reserved.\n */\n",
};
4 changes: 2 additions & 2 deletions packages/node-build-scripts/es-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ 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)
const anyFilesToLint = glob.sync(absoluteFileGlob);
if (anyFilesToLint.length === 0) {
console.log(`[node-build-scripts] 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 Down
8 changes: 3 additions & 5 deletions packages/node-build-scripts/generate-icons-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,16 @@ writeLinesToFile(
// map ENUM_NAME to unicode character
writeLinesToFile(
"iconContents.ts",
...ICONS_WITH_FONT_SUPPORT.map(icon =>
`export const ${toEnumName(icon)} = "${icon.content.replace("\\", "\\u")}";`,
...ICONS_WITH_FONT_SUPPORT.map(
icon => `export const ${toEnumName(icon)} = "${icon.content.replace("\\", "\\u")}";`,
),
);

// map ENUM_NAME to icon-name, must include ALL icons (not just those with font support)
// so that we can reference their SVG paths
writeLinesToFile(
"iconNames.ts",
...ICONS_METADATA.map(icon =>
`export const ${toEnumName(icon)} = "${icon.iconName}";`,
),
...ICONS_METADATA.map(icon => `export const ${toEnumName(icon)} = "${icon.iconName}";`),
);

(async () => {
Expand Down
10 changes: 2 additions & 8 deletions packages/node-build-scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ const path = require("path");
* @param {string} fileName name of XML file (defaults to current directory name).
*/
function junitReportPath(dirName, fileName = path.basename(process.cwd())) {
return path.join(
__dirname,
"../..",
process.env.JUNIT_REPORT_PATH,
dirName,
`${fileName}.xml`,
);
return path.join(__dirname, "../..", process.env.JUNIT_REPORT_PATH, dirName, `${fileName}.xml`);
}

module.exports = { junitReportPath }
module.exports = { junitReportPath };
10 changes: 3 additions & 7 deletions packages/webpack-build-scripts/webpack.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/

const path = require("path");
const webpack = require("webpack");

// webpack plugins
const { CheckerPlugin } = require("awesome-typescript-loader");
Expand Down Expand Up @@ -51,7 +50,7 @@ const plugins = [
if (!IS_PRODUCTION) {
plugins.push(
// Trigger an OS notification when the build succeeds in dev mode.
new WebpackNotifierPlugin({ title: PACKAGE_NAME })
new WebpackNotifierPlugin({ title: PACKAGE_NAME }),
);
}

Expand All @@ -70,10 +69,7 @@ const scssLoaders = [
{
loader: require.resolve("postcss-loader"),
options: {
plugins: [
require("autoprefixer"),
require("cssnano")({ preset: "default" }),
],
plugins: [require("autoprefixer"), require("cssnano")({ preset: "default" })],
},
},
require.resolve("sass-loader"),
Expand Down Expand Up @@ -129,6 +125,6 @@ module.exports = {
plugins,

resolve: {
extensions: [ ".js", ".jsx", ".ts", ".tsx", ".scss" ],
extensions: [".js", ".jsx", ".ts", ".tsx", ".scss"],
},
};
Loading

1 comment on commit f4e58c6

@blueprint-bot
Copy link

Choose a reason for hiding this comment

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

chore: reconfigure ESLint again, move prettier to monorepo root (#4080)

Previews: documentation | landing | table

Please sign in to comment.