Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettier + ESLint setup #16514

Merged
merged 4 commits into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .eslintrc

This file was deleted.

33 changes: 33 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module.exports = {
extends: [
'@elastic/eslint-config-kibana',
'@elastic/eslint-config-kibana/jest',
],

settings: {
'import/resolver': {
'@elastic/eslint-import-resolver-kibana': {
rootPackageName: 'kibana',
kibanaPath: '.',
},
},
},

overrides: [
// Enable Prettier
{
files: [
'.eslintrc.js',
'packages/kbn-build/**/*.js',
],
plugins: [
'prettier',
],
rules: Object.assign(
{ 'prettier/prettier': 'error' },
require('eslint-config-prettier').rules,
require('eslint-config-prettier/react').rules,
),
},
]
}
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "es5"
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@
"url": "https://github.com/elastic/kibana.git"
},
"dependencies": {
"@kbn/babel-preset": "link:packages/kbn-babel-preset",
"@elastic/datemath": "4.0.2",
"@elastic/eui": "0.0.18",
"@elastic/filesaver": "1.1.2",
"@elastic/numeral": "2.3.1",
"@elastic/test-subj-selector": "0.2.1",
"@elastic/ui-ace": "0.2.3",
"@kbn/babel-preset": "link:packages/kbn-babel-preset",
"JSONStream": "1.1.1",
"accept-language-parser": "1.2.0",
"angular": "1.6.5",
Expand Down Expand Up @@ -233,11 +233,13 @@
"enzyme-adapter-react-16": "^1.1.1",
"enzyme-to-json": "3.1.4",
"eslint": "4.14.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-babel": "4.1.2",
"eslint-plugin-import": "2.8.0",
"eslint-plugin-jest": "^21.6.2",
"eslint-plugin-mocha": "4.11.0",
"eslint-plugin-prefer-object-spread": "1.2.1",
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-react": "7.5.1",
"event-stream": "3.3.2",
"expect.js": "0.3.1",
Expand Down Expand Up @@ -286,6 +288,7 @@
"nock": "8.0.0",
"node-sass": "4.5.3",
"pixelmatch": "4.0.2",
"prettier": "^1.10.2",
"proxyquire": "1.7.10",
"sass-loader": "6.0.6",
"simple-git": "1.37.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-build/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export async function run(argv) {

const options = getopts(argv, {
alias: {
h: 'help'
}
h: 'help',
},
});

const args = options._;
Expand Down
12 changes: 6 additions & 6 deletions packages/kbn-build/src/production/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { getProjects } from '../../utils/projects';
// and more integration-y, as we're trying to not add very slow tests to our
// Jest unit tests.

describe('kbn-build production', function () {
it('builds and copies projects for production', async function () {
describe('kbn-build production', function() {
it('builds and copies projects for production', async function() {
this.timeout(60 * 1000);

const tmpDir = tempy.directory();
Expand All @@ -26,22 +26,22 @@ describe('kbn-build production', function () {
cwd: fixturesPath,
parents: true,
nodir: true,
dot: true
dot: true,
});

const projects = await getProjects(tmpDir, ['./packages/*']);

for (const project of projects.values()) {
// This will both install dependencies and generate `yarn.lock` files
await project.installDependencies({
extraArgs: ['--silent', '--no-progress']
extraArgs: ['--silent', '--no-progress'],
});
}

await buildProductionProjects({ kibanaRoot: tmpDir, buildRoot });

const files = await globby(['**/*', '!**/node_modules/**'], {
cwd: buildRoot
cwd: buildRoot,
});

expect(files).to.eql([
Expand All @@ -52,7 +52,7 @@ describe('kbn-build production', function () {
'packages/foo/package.json',
'packages/foo/src/index.js',
'packages/foo/target/index.js',
'packages/foo/yarn.lock'
'packages/foo/yarn.lock',
]);
});
});
8 changes: 4 additions & 4 deletions packages/kbn-build/src/production/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import { getProjectPaths } from '../config';
import {
getProjects,
buildProjectGraph,
topologicallyBatchProjects
topologicallyBatchProjects,
} from '../utils/projects';
import {
createProductionPackageJson,
writePackageJson
writePackageJson,
} from '../utils/package_json';
import { isDirectory } from '../utils/fs';

export async function buildProductionProjects({ kibanaRoot, buildRoot }) {
const projectPaths = getProjectPaths(kibanaRoot, {
'skip-kibana': true,
'skip-kibana-extra': true
'skip-kibana-extra': true,
});

const projects = await getProductionProjects(kibanaRoot, projectPaths);
Expand Down Expand Up @@ -81,7 +81,7 @@ async function copyToBuild(project, kibanaRoot, buildRoot) {
cwd: project.path,
parents: true,
nodir: true,
dot: true
dot: true,
});

const packageJson = project.json;
Expand Down
6 changes: 3 additions & 3 deletions packages/kbn-build/src/utils/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function generateColors() {
export function spawn(command, args, opts) {
return execa(command, args, {
...opts,
stdio: 'inherit'
stdio: 'inherit',
});
}

Expand All @@ -25,14 +25,14 @@ const nextColor = generateColors();
export function spawnStreaming(command, args, opts, { prefix }) {
const spawned = execa(command, args, {
...opts,
stdio: ['ignore', 'pipe', 'pipe']
stdio: ['ignore', 'pipe', 'pipe'],
});

const color = nextColor();
const prefixedStdout = logTransformer({ tag: `${color.bold(prefix)}:` });
const prefixedStderr = logTransformer({
tag: `${logSymbols.error} ${color.bold(prefix)}:`,
mergeMultiline: true
mergeMultiline: true,
});

spawned.stdout.pipe(prefixedStdout).pipe(process.stdout);
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-build/src/utils/package_json.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function writePackageJson(path, json) {

export const createProductionPackageJson = pkgJson => ({
...pkgJson,
dependencies: transformDependencies(pkgJson.dependencies)
dependencies: transformDependencies(pkgJson.dependencies),
});

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/kbn-build/src/utils/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import chalk from 'chalk';
import {
installInDir,
runScriptInPackage,
runScriptInPackageStreaming
runScriptInPackageStreaming,
} from './scripts';
import { readPackageJson } from './package_json';
import { CliError } from './errors';
Expand All @@ -27,7 +27,7 @@ export class Project {

this.allDependencies = {
...(this.json.devDependencies || {}),
...(this.json.dependencies || {})
...(this.json.dependencies || {}),
};

this.scripts = this.json.scripts || {};
Expand All @@ -53,7 +53,7 @@ export class Project {
const meta = {
package: `${this.name} (${this.packageJsonLocation})`,
expected: `"${project.name}": "${expectedVersionInPackageJson}"`,
actual: `"${project.name}": "${versionInPackageJson}"`
actual: `"${project.name}": "${versionInPackageJson}"`,
};

if (versionInPackageJson.startsWith(PREFIX)) {
Expand Down
26 changes: 13 additions & 13 deletions packages/kbn-build/src/utils/project.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const createProjectWith = (fields, path = '') =>
{
name: 'kibana',
version: '1.0.0',
...fields
...fields,
},
join(rootPath, path)
);
Expand All @@ -25,11 +25,11 @@ describe('fromPath', () => {
test('fields', async () => {
const kibana = createProjectWith({
scripts: {
test: 'jest'
test: 'jest',
},
dependencies: {
foo: '1.2.3'
}
foo: '1.2.3',
},
});

expect(kibana.name).toBe('kibana');
Expand All @@ -45,13 +45,13 @@ describe('#ensureValidProjectDependency', () => {
test('valid link: version', async () => {
const root = createProjectWith({
dependencies: {
foo: 'link:packages/foo'
}
foo: 'link:packages/foo',
},
});

const foo = createProjectWith(
{
name: 'foo'
name: 'foo',
},
'packages/foo'
);
Expand All @@ -63,15 +63,15 @@ describe('#ensureValidProjectDependency', () => {
const root = createProjectWith(
{
dependencies: {
foo: 'link:wrong/path'
}
foo: 'link:wrong/path',
},
},
rootPath
);

const foo = createProjectWith(
{
name: 'foo'
name: 'foo',
},
'packages/foo'
);
Expand All @@ -85,15 +85,15 @@ describe('#ensureValidProjectDependency', () => {
const root = createProjectWith(
{
dependencies: {
foo: '1.0.0'
}
foo: '1.0.0',
},
},
rootPath
);

const foo = createProjectWith(
{
name: 'foo'
name: 'foo',
},
'packages/foo'
);
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-build/src/utils/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function getProjects(rootPath, projectsPaths) {

// Do not match ** against multiple filenames
// (This is only specified because we currently don't have a need for it.)
noglobstar: true
noglobstar: true,
};
const projects = new Map();

Expand All @@ -36,7 +36,7 @@ export async function getProjects(rootPath, projectsPaths) {
`There are multiple projects with the same name [${project.name}]`,
{
name: project.name,
paths: [project.path, projects.get(project.name).path]
paths: [project.path, projects.get(project.name).path],
}
);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/kbn-build/src/utils/projects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { resolve } from 'path';
import {
getProjects,
buildProjectGraph,
topologicallyBatchProjects
topologicallyBatchProjects,
} from './projects';

const rootPath = resolve(`${__dirname}/__fixtures__/kibana`);
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('#buildProjectGraph', () => {
const projects = await getProjects(rootPath, [
'.',
'packages/*',
'../plugins/*'
'../plugins/*',
]);
const graph = buildProjectGraph(projects);

Expand All @@ -71,7 +71,7 @@ describe('#topologicallyBatchProjects', () => {
const projects = await getProjects(rootPath, [
'.',
'packages/*',
'../plugins/*'
'../plugins/*',
]);
const graph = buildProjectGraph(projects);

Expand Down
10 changes: 5 additions & 5 deletions packages/kbn-build/src/utils/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export function installInDir(directory, extraArgs = []) {
'install',
'--non-interactive',
'--mutex file',
...extraArgs
...extraArgs,
];

// We pass the mutex flag to ensure only one instance of yarn runs at any
// given time (e.g. to avoid conflicts).
return spawn(yarnPath, options, {
cwd: directory
cwd: directory,
});
}

Expand All @@ -24,7 +24,7 @@ export function installInDir(directory, extraArgs = []) {
*/
export function runScriptInPackage(script, args, pkg) {
const execOpts = {
cwd: pkg.path
cwd: pkg.path,
};

return spawn(yarnPath, ['run', script, ...args], execOpts);
Expand All @@ -35,10 +35,10 @@ export function runScriptInPackage(script, args, pkg) {
*/
export function runScriptInPackageStreaming(script, args, pkg) {
const execOpts = {
cwd: pkg.path
cwd: pkg.path,
};

return spawnStreaming(yarnPath, ['run', script, ...args], execOpts, {
prefix: pkg.name
prefix: pkg.name,
});
}
Loading