Skip to content

Commit

Permalink
[eslint] fix root-level and package linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Aug 22, 2018
1 parent c0f6e01 commit 6db69c3
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 50 deletions.
44 changes: 25 additions & 19 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,38 @@
},
"rules": {
"id-length": 0,
"new-cap": [2, { "capIsNewExceptions": ["AND"] }],
"react/jsx-pascal-case": [2, { "allowAllCaps": true }],
"react/no-find-dom-node": 1,
"import/first": 0,
"no-underscore-dangle": [2, {
"allowAfterThis": true,
"allow": [
"_context",
"_currentElement",
"_instance",
"_reactInternalComponent",
"_reactInternalInstance",
"_renderedChildren",
"_renderedComponent",
"_renderedNodeType",
"_state",
"_store",
"_stringText",
],
}],
},
"overrides": [
{ // things that run in older envs, without babel
"files": [
"env.js",
"karma.conf.js",
],
"rules": {
"import/no-extraneous-dependencies": [2, {
"devDependencies": true,
}],
"comma-dangle": [2, {
arrays: "always-multiline",
objects: "always-multiline",
imports: "always-multiline",
exports: "always-multiline",
functions: "ignore",
}],
"strict": [2, "safe"],
"prefer-destructuring": 0,
"prefer-template": 0,
},
"parserOptions": {
sourceType: "script",
},
},
{
"files": [
"*.md",
//"**/*.md",
"**/*.md",
],
"plugins": [
"markdown"
Expand Down
26 changes: 15 additions & 11 deletions env.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
'use strict';

const path = require('path');
const fs = require('fs');
const child_process = require('child_process');
const spawn = require('child_process').spawn;
const rimraf = require('rimraf');

const promisify = fn => new Promise((res, rej) => {
const done = (err, val) => (err ? rej(err) : res(val));
fn(done);
});
const getJSON = fpath => getFile(fpath).then(json => JSON.parse(json));
const getFile = fpath => promisify(cb => fs.readFile(fpath, 'utf8', cb));
const getFiles = fpath => promisify(cb => fs.readdir(fpath, cb));
// const getFiles = fpath => promisify(cb => fs.readdir(fpath, cb));
const getJSON = fpath => getFile(fpath).then(json => JSON.parse(json));
const writeFile = (fpath, src) => promisify(cb => fs.writeFile(fpath, src, cb));
const writeJSON = (fpath, json, pretty = false) => writeFile(
fpath,
pretty
? JSON.stringify(json, null, 2)
: JSON.stringify(json)
);
const primraf = path => promisify(cb => rimraf(path, cb));
const run = (cmd, ...args) => promisify(cb => {
const child = child_process.spawn(cmd, args, { stdio: 'inherit' });
const primraf = fpath => promisify(cb => rimraf(fpath, cb));
const run = (cmd, ...args) => promisify((cb) => {
const child = spawn(cmd, args, { stdio: 'inherit' });
child.on('exit', cb);
});

Expand All @@ -37,10 +39,10 @@ const version = process.argv[2];
// 5. call lerna bootstrap to link all the packages
// 6. install all of the package's peer deps at the top level

var root = process.cwd();
var adapterName = `enzyme-adapter-react-${version}`;
var adapterPackageJsonPath = path.join(root, 'packages', adapterName, 'package.json');
var testPackageJsonPath = path.join(root, 'packages', 'enzyme-test-suite', 'package.json');
const root = process.cwd();
const adapterName = `enzyme-adapter-react-${version}`;
const adapterPackageJsonPath = path.join(root, 'packages', adapterName, 'package.json');
const testPackageJsonPath = path.join(root, 'packages', 'enzyme-test-suite', 'package.json');

if (!fs.statSync(adapterPackageJsonPath)) {
throw new Error('Adapter not found: "' + adapterName + '"');
Expand Down Expand Up @@ -76,6 +78,7 @@ Promise.resolve()
.filter(key => !key.startsWith('enzyme'))
.map(key => `${key}@${peerDeps[key]}`);

// eslint-disable-next-line no-param-reassign
testJson.dependencies[adapterName] = adapterJson.version;

return Promise.all([
Expand All @@ -88,9 +91,10 @@ Promise.resolve()
})
.then(() => run('lerna', 'bootstrap'))
.then(() => getJSON(testPackageJsonPath))
.then(testJson => {
.then((testJson) => {
// now that we've lerna bootstrapped, we can remove the adapter from the
// package.json so there is no diff
// eslint-disable-next-line no-param-reassign
delete testJson.dependencies[adapterName];
return writeJSON(testPackageJsonPath, testJson, true);
})
Expand Down
2 changes: 2 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable no-var,prefer-arrow-callback,vars-on-top, import/no-extraneous-dependencies */

'use strict';

require('babel-register');

var IgnorePlugin = require('webpack').IgnorePlugin;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
"postversion": "git push && git push --tags && npm run clean && npm run docs:publish",
"version": "lerna run build",
"clean": "lerna run clean",
"prelint": "npm run docs:lint",
"prelint": "npm run lint:root",
"lint": "lerna exec --parallel 'npm run lint -- --quiet'",
"lint:root": "eslint . --ext=js,md,jsx --ignore-pattern=packages/ --ignore-path .eslintignore",
"check": "lerna run lint && npm run test:all",
"prebuild": "npm run clean",
"build": "lerna run build",
Expand All @@ -38,7 +39,6 @@
"react:16": "npm run env -- 16",
"env": "babel-node ./env.js",
"docs:clean": "rimraf _book",
"docs:lint": "eslint --ext md --ignore-path .eslintignore .",
"docs:prepare": "gitbook install",
"docs:build": "npm run docs:prepare && gitbook build",
"docs:watch": "npm run docs:prepare && gitbook serve",
Expand Down
8 changes: 5 additions & 3 deletions packages/enzyme-adapter-react-13/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"extends": "airbnb",
"root": true,
"rules": {
"react/no-find-dom-node": 0,
"react/no-multi-comp": 0,
Expand All @@ -7,7 +9,7 @@
},
"settings": {
"react": {
"version": "0.13.0"
}
}
"version": "0.13.0",
},
},
}
8 changes: 5 additions & 3 deletions packages/enzyme-adapter-react-14/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"extends": "airbnb",
"root": true,
"rules": {
"react/no-find-dom-node": 0,
"react/no-multi-comp": 0,
Expand All @@ -7,7 +9,7 @@
},
"settings": {
"react": {
"version": "0.14.0"
}
}
"version": "0.14.0",
},
},
}
8 changes: 5 additions & 3 deletions packages/enzyme-adapter-react-15.4/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"extends": "airbnb",
"root": true,
"rules": {
"react/no-find-dom-node": 0,
"react/no-multi-comp": 0,
Expand All @@ -7,7 +9,7 @@
},
"settings": {
"react": {
"version": "16.0.0"
}
}
"version": "15.4.0",
},
},
}
8 changes: 5 additions & 3 deletions packages/enzyme-adapter-react-15/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"extends": "airbnb",
"root": true,
"rules": {
"react/no-find-dom-node": 0,
"react/no-multi-comp": 0,
Expand All @@ -7,7 +9,7 @@
},
"settings": {
"react": {
"version": "15.5.0"
}
}
"version": "15.5.0",
},
},
}
9 changes: 8 additions & 1 deletion packages/enzyme-adapter-react-16.1/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"extends": "airbnb",
"root": true,
"rules": {
"import/no-extraneous-dependencies": 0,
"import/no-unresolved": 0,
Expand All @@ -8,5 +10,10 @@
"react/no-multi-comp": 0,
"no-underscore-dangle": 0,
"class-methods-use-this": 0
}
},
"settings": {
"react": {
"version": "16.1.0",
},
},
}
9 changes: 8 additions & 1 deletion packages/enzyme-adapter-react-16.2/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"extends": "airbnb",
"root": true,
"rules": {
"import/no-extraneous-dependencies": 0,
"import/no-unresolved": 0,
Expand All @@ -8,5 +10,10 @@
"react/no-multi-comp": 0,
"no-underscore-dangle": 0,
"class-methods-use-this": 0
}
},
"settings": {
"react": {
"version": "16.2.0",
},
},
}
9 changes: 8 additions & 1 deletion packages/enzyme-adapter-react-16.3/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"extends": "airbnb",
"root": true,
"rules": {
"import/no-extraneous-dependencies": 0,
"import/no-unresolved": 0,
Expand All @@ -8,5 +10,10 @@
"react/no-multi-comp": 0,
"no-underscore-dangle": 0,
"class-methods-use-this": 0
}
},
"settings": {
"react": {
"version": "16.3.0",
},
},
}
9 changes: 8 additions & 1 deletion packages/enzyme-adapter-react-16/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"extends": "airbnb",
"root": true,
"rules": {
"import/no-extraneous-dependencies": 0,
"import/no-unresolved": 0,
Expand All @@ -8,5 +10,10 @@
"react/no-multi-comp": 0,
"no-underscore-dangle": 0,
"class-methods-use-this": 0
}
},
"settings": {
"react": {
"version": "16.4.0",
},
},
}
12 changes: 12 additions & 0 deletions packages/enzyme-adapter-utils/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "airbnb",
"root": true,
"overrides": [
{
"files": ["src/createMountWrapper.*"],
"rules": {
"no-underscore-dangle": 0,
},
},
],
}
4 changes: 2 additions & 2 deletions packages/enzyme-example-mocha/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"root": true,
"env": {
"node": true,
"mocha": true
}
"mocha": true,
},
}

0 comments on commit 6db69c3

Please sign in to comment.