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

build(eslint) add eslint plugins for node and mocha #25

Merged
merged 3 commits into from
Nov 26, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
build(eslint): add 'import' plugin
  • Loading branch information
sverweij committed Nov 26, 2017
commit 784fa6697f70b5320afb782955d893a46fb3048d
43 changes: 41 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"plugins": [
"security",
"mocha",
"node"
"node",
"import"
],
"parserOptions": {
"ecmaVersion": 6,
Expand Down Expand Up @@ -279,7 +280,45 @@
"node/no-unpublished-require": "error",
"node/no-unsupported-features": "error",
"node/process-exit-as-throw": "error",
"node/shebang": "error"
"node/shebang": "error",

// imports
"import/no-unresolved": "error",
"import/named": "error",
"import/default": "error",
"import/namespace": "error",
"import/no-stricted-paths": "off",
"import/no-absolute-path": "error",
"import/no-dynamic-require": "error",
"import/no-internal-modules": "off",
"import/no-webpack-loader-syntax": "error",

"import/export": "error",
"import/no-named-as-default": "error",
"import/no-named-as-default-member": "error",
"import/no-deprecated": "error",
"import/no-extraneous-dependencies": "error",
"import/no-mutable-exports": "error",

"import/unambiguous": "off",
"import/no-commonjs": "off",
"import/no-amd": "error",
"import/no-nodejs-modules": "off",

"import/first": "error",
"import/exports-last": "error",
"import/no-duplicates": "error",
"import/no-namespace": "error",
"import/extensions": "off",
"import/order": "error",
"import/newline-after-import": "error",
"import/prefer-default-export": "error",
"import/max-dependencies": ["error", {"max": 20}],
"import/no-unassigned-import": "error",
"import/no-named-default": "error",
"import/no-anonymous-default-export": "error"
// "import/group-exports": "error"

},
"env": {
"node": true,
Expand Down
2 changes: 1 addition & 1 deletion bin/dependency-cruise
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"use strict";

const program = require("commander");
const semver = require("semver");
const processCLI = require("../src/cli");
const $package = require("../package.json");
const semver = require("semver");

/* istanbul ignore if */
if (!semver.satisfies(process.versions.node, $package.engines.node)) {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"scripts": {
"depcruise": "./bin/dependency-cruise -X ^node_modules -x fixtures -v .dependency-cruiser-custom.json src bin/dependency-cruise test",
"depcruise:graph": "./bin/dependency-cruise -x \"(^node_modules|^fs$|^path$)\" -T dot -v .dependency-cruiser-custom.json bin/dependency-cruise | dot -T svg > tmp_deps.svg",
"lint": "eslint bin src test",
"lint:fix": "eslint --fix bin src test",
"lint": "eslint bin/dependency-cruise src test",
"lint:fix": "eslint --fix bin/dependency-cruise src test",
"nsp": "nsp check",
"npm-check-updates": "ncu --upgrade",
"postversion": "git push && git push --tags && npm publish",
Expand Down Expand Up @@ -42,6 +42,7 @@
"chai-json-schema": "1.5.0",
"coffee-script": "1.12.7",
"eslint": "4.12.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-mocha": "4.11.0",
"eslint-plugin-node": "5.2.1",
"eslint-plugin-security": "1.4.0",
Expand Down
2 changes: 1 addition & 1 deletion src/cli/formatMetaInfo.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use strict";

const main = require("../main");
const chalk = require('chalk');
const figures = require('figures');
const main = require("../main");

function bool2Symbol(pBool) {
return pBool ? chalk.green(figures.tick) : chalk.red(figures.cross);
Expand Down
12 changes: 6 additions & 6 deletions src/cli/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"use strict";

const fs = require('fs');
const fs = require('fs');
const main = require('../main');
const validateFileExistence = require('./validateFileExistence');
const normalizeOptions = require('./normalizeOptions');
const initRules = require('./initRules');
const main = require('../main');
const formatMetaInfo = require('./formatMetaInfo');
const defaults = require('./defaults.json');
const normalizeOptions = require('./normalizeOptions');
const initRules = require('./initRules');
const formatMetaInfo = require('./formatMetaInfo');
const defaults = require('./defaults.json');

function writeToFile(pOutputTo, pDependencyString) {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/extract/extract.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use strict";

const fs = require('fs');
const path = require('path');
const acorn = require('acorn');
const acorn_loose = require('acorn/dist/acorn_loose');
const fs = require('fs');
const _ = require('lodash');
const path = require('path');
const resolve = require('./resolve');
const transpile = require('./transpile');
const ignore = require('./ignore');
Expand Down
3 changes: 2 additions & 1 deletion src/extract/gatherInitialSources.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const fs = require('fs');
const path = require('path');
const _defaults = require('lodash/defaults');
const ignore = require('./ignore');
const transpileMeta = require('./transpile/meta');
const _defaults = require('lodash/defaults');


const SUPPORTED_EXTENSIONS = transpileMeta.scannableExtensions;

Expand Down
2 changes: 1 addition & 1 deletion src/extract/resolve/resolve-AMD.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use strict";

const fs = require('fs');
const path = require('path');
const resolve = require('resolve');
const fs = require('fs');
const memoize = require('lodash/memoize');
const determineDependencyTypes = require('./determineDependencyTypes');
const readPackageDeps = require('./readPackageDeps');
Expand Down
2 changes: 2 additions & 0 deletions src/extract/transpile/coffeeWrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ module.exports = (pLiterate) => ({
return coffeeScript.compile(pFile, lOptions);
}
});

/* eslint import/order: off */
4 changes: 3 additions & 1 deletion src/extract/transpile/liveScriptWrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ const livescript = tryRequire(
require("../../../package.json").supportedTranspilers.livescript
);

/* istanbul ignore next */
module.exports = {
isAvailable: () => livescript !== false,

/* istanbul ignore next */
transpile: pFile =>
livescript.compile(
pFile
)
};

/* eslint import/order: off */
2 changes: 1 addition & 1 deletion src/extract/transpile/meta.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"use strict";

const supportedTranspilers = require("../../../package.json").supportedTranspilers;
const javaScriptWrap = require("./javaScriptWrap");
const typeScriptWrap = require("./typeScriptWrap");
const liveScriptWrap = require("./liveScriptWrap");
const coffeeWrap = require("./coffeeWrap")();
const litCoffeeWrap = require("./coffeeWrap")(true);
const supportedTranspilers = require("../../../package.json").supportedTranspilers;

/*
jsx - acorn_loose will handle this correctly when imports
Expand Down
1 change: 1 addition & 0 deletions src/extract/transpile/tryRequire.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ module.exports = (pModuleName, pSemVer) => {
eslint
global-require: 0,
security/detect-non-literal-require: 0
import/no-dynamic-require: 0
*/
2 changes: 2 additions & 0 deletions src/extract/transpile/typeScriptWrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ module.exports = {
}
).outputText
};

/* eslint import/order: off */
4 changes: 2 additions & 2 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

const extract = require("../extract");
const meta = require("../extract/transpile/meta");
const validateRuleSet = require("./ruleSet/validate");
const normalizeRuleSet = require("./ruleSet/normalize");
const reportHtml = require("../report/htmlReporter");
const reportJson = require("../report/jsonReporter");
const reportDot = require("../report/dotReporter");
const reportCsv = require("../report/csvReporter");
const reportErr = require("../report/errReporter");
const validateRuleSet = require("./ruleSet/validate");
const normalizeRuleSet = require("./ruleSet/normalize");
const validateOptions = require("./options/validate");
const normalizeOptions = require("./options/normalize");

Expand Down
2 changes: 2 additions & 0 deletions src/report/csvReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ module.exports = pInput =>
})
}
);

/* eslint import/no-unassigned-import: 0 */
2 changes: 2 additions & 0 deletions src/report/dotReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,5 @@ module.exports = (pInput) =>
})
}
);

/* eslint import/no-unassigned-import: 0 */
3 changes: 3 additions & 0 deletions src/report/htmlReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ module.exports = pInput =>
})
}
);


/* eslint import/no-unassigned-import: 0 */
6 changes: 3 additions & 3 deletions test/cli/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"use strict";
const fs = require("fs");
const path = require("path");
const expect = require('chai').expect;
const intercept = require("intercept-stdout");
const processCLI = require("../../src/cli");
const fs = require("fs");
const tst = require("../utl/testutensils");
const deleteDammit = require("./deleteDammit.utl");
const path = require("path");
const intercept = require("intercept-stdout");

const OUT_DIR = "./test/cli/output";
const FIX_DIR = "./test/cli/fixtures";
Expand Down
6 changes: 3 additions & 3 deletions test/cli/initRules.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"use strict";
const chai = require('chai');
const expect = chai.expect;
const fs = require('fs');
const deleteDammit = require("./deleteDammit.utl");
const chai = require('chai');
const initRules = require("../../src/cli/initRules");
const rulesSchema = require('../../src/main/ruleSet/jsonschema.json');
const deleteDammit = require("./deleteDammit.utl");

const expect = chai.expect;
const RULES_FILE = ".dependency-cruiser.json";

chai.use(require('chai-json-schema'));
Expand Down
5 changes: 3 additions & 2 deletions test/extract/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"use strict";

const chai = require('chai');
const expect = chai.expect;
const extract = require('../../src/extract');
const depSchema = require('../../src/extract/jsonschema.json');
const cjsRecursiveFixtures = require('./fixtures/cjs-recursive.json');
const deprecationFixtures = require('./fixtures/deprecated-node-module.json');
const bundledFixtures = require('./fixtures/bundled-dependencies.json');
const amdRecursiveFixtures = require('./fixtures/amd-recursive.json');
const tsRecursiveFixtures = require('./fixtures/ts-recursive.json');
const coffeeRecursiveFixtures = require('./fixtures/coffee-recursive.json');
const depSchema = require('../../src/extract/jsonschema.json');

const expect = chai.expect;

chai.use(require('chai-json-schema'));

Expand Down
2 changes: 1 addition & 1 deletion test/extract/resolve/readPackageDeps.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

const expect = require("chai").expect;
const path = require("path");
const expect = require("chai").expect;
const read = require("../../../src/extract/resolve/readPackageDeps");

const FIXTUREDIR = "test/extract/resolve/fixtures/";
Expand Down
2 changes: 1 addition & 1 deletion test/extract/transpile/coffeeWrap.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

const expect = require("chai").expect;
const fs = require('fs');
const expect = require("chai").expect;
const wrap = require("../../../src/extract/transpile/coffeeWrap")();
const litWrap = require("../../../src/extract/transpile/coffeeWrap")(true);

Expand Down
2 changes: 1 addition & 1 deletion test/extract/transpile/javascriptWrap.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

const expect = require("chai").expect;
const fs = require('fs');
const expect = require("chai").expect;
const wrap = require("../../../src/extract/transpile/javaScriptWrap");

describe("jsx transpiler (the plain old javascript one)", () => {
Expand Down
3 changes: 2 additions & 1 deletion test/extract/transpile/tryRequire.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"use strict";

const expect = require("chai").expect;
const tryRequire = require("../../../src/extract/transpile/tryRequire");
const semver = require('semver');
const tryRequire = require("../../../src/extract/transpile/tryRequire");


describe("transpiler tryRequire", () => {
it("returns false for unresolvable modules", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/extract/transpile/typeScriptWrap.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

const expect = require("chai").expect;
const fs = require('fs');
const expect = require("chai").expect;
const wrap = require("../../../src/extract/transpile/typeScriptWrap");

describe("typescript transpiler", () => {
Expand Down
5 changes: 3 additions & 2 deletions test/main/main.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"use strict";
const chai = require('chai');
const expect = chai.expect;
const main = require("../../src/main");
const depSchema = require('../../src/extract/jsonschema.json');
const tsFixture = require('./fixtures/ts.json');
const tsxFixture = require('./fixtures/tsx.json');
const jsxFixture = require('./fixtures/jsx.json');
const depSchema = require('../../src/extract/jsonschema.json');

const expect = chai.expect;

chai.use(require('chai-json-schema'));

Expand Down
2 changes: 1 addition & 1 deletion test/main/options/normalize.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const normalizeOptions = require('../../../src/main/options/normalize');
const expect = require('chai').expect;
const normalizeOptions = require('../../../src/main/options/normalize');

describe("main/normalizeOptions", () => {
it("ensures maxDepth is an int when passed an int", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/main/ruleSet/validate.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";
const fs = require('fs');
const expect = require('chai').expect;
const validate = require('../../../src/main/ruleSet/validate');
const fs = require('fs');

describe("ruleSetReader", () => {
it("bails out on scary regexps in paths", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/utl/testutensils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const expect = require('chai').expect;
const fs = require("fs");
const expect = require('chai').expect;

module.exports = (() => {
"use strict";
Expand Down
2 changes: 1 addition & 1 deletion test/validate/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict";
const fs = require('fs');
const expect = require('chai').expect;
const validate = require('../../src/validate');
const normalizeRuleSet = require('../../src/main/ruleSet/normalize');
const validateRuleSet = require('../../src/main/ruleSet/validate');
const fs = require('fs');

function _readRuleSet(pFileName) {
return normalizeRuleSet(
Expand Down