Skip to content
This repository was archived by the owner on Nov 22, 2021. It is now read-only.

Chore: switch to eslint-config-eslint #9

Merged
merged 4 commits into from
May 16, 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
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": ["mysticatea", "mysticatea/node"]
"extends": ["eslint", "plugin:node/recommended"],
"plugins": ["node"]
}
30 changes: 15 additions & 15 deletions bin/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
* @author Toru Nagashima
* See LICENSE file in root directory for full license.
*/
"use strict"
"use strict";

const debug = require("debug")("eslint-cli")
const debugMode = process.argv.indexOf("--debug") !== -1
const cwd = process.cwd()
const debug = require("debug")("eslint-cli");
const debugMode = process.argv.indexOf("--debug") !== -1;
const cwd = process.cwd();

if (debugMode) {
require("debug").enable("eslint-cli")
require("debug").enable("eslint-cli");
}

debug("START", process.argv)
debug("ROOT", cwd)
debug("START", process.argv);
debug("ROOT", cwd);

const binPath = require("../lib/get-local-eslint")(cwd) || require("../lib/get-bin-eslint-js")(cwd)
if (binPath != null) {
require(binPath)
}
else {
//eslint-disable-next-line no-console
const binPath = require("../lib/get-local-eslint")(cwd) || require("../lib/get-bin-eslint-js")(cwd);

if (binPath !== null) {
require(binPath);
} else {
// eslint-disable-next-line no-console
console.error(`
Could not find local ESLint.
Please install ESLint by 'npm install --save-dev eslint'.
`)
process.exitCode = 1
`);
process.exitCode = 1;
}
38 changes: 20 additions & 18 deletions lib/get-bin-eslint-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* @author Toru Nagashima
* See LICENSE file in root directory for full license.
*/
"use strict"
"use strict";

const fs = require("fs")
const path = require("path")
const debug = require("debug")("eslint-cli")
const fs = require("fs");
const path = require("path");
const debug = require("debug")("eslint-cli");

/**
* Finds and tries executing "./bin/eslint.js".
Expand All @@ -17,28 +17,30 @@ const debug = require("debug")("eslint-cli")
* @param {string} basedir - A path of the directory that it starts searching.
* @returns {string|null} The path of "./bin/eslint.js"
*/
module.exports = (basedir) => {
let dir = basedir
let prevDir = dir
module.exports = basedir => {
let dir = basedir;
let prevDir = dir;

do {
const binPath = path.join(dir, "bin", "eslint.js")
const binPath = path.join(dir, "bin", "eslint.js");

if (fs.existsSync(binPath)) {
debug("FOUND '%s'", binPath)
return binPath
debug("FOUND '%s'", binPath);
return binPath;
}
debug("NOT FOUND '%s'", binPath)
debug("NOT FOUND '%s'", binPath);

// Finish if package.json is found.
if (fs.existsSync(path.join(dir, "package.json"))) {
break
break;
}

// Go to next.
prevDir = dir
dir = path.resolve(dir, "..")
prevDir = dir;
dir = path.resolve(dir, "..");
}
while (dir !== prevDir)
while (dir !== prevDir);

debug("NOT FOUND './bin/eslint.js'")
return null
}
debug("NOT FOUND './bin/eslint.js'");
return null;
};
26 changes: 13 additions & 13 deletions lib/get-local-eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
"use strict";

const debug = require("debug")("eslint-cli")
const resolve = require("resolve")
const debug = require("debug")("eslint-cli");
const resolve = require("resolve");

/**
* Finds and tries executing a local eslint module.
*
* @param {string} basedir - A path of the directory that it starts searching.
* @returns {string|null} The path of a local eslint module.
*/
module.exports = (basedir) => {
module.exports = basedir => {
try {
const binPath = resolve.sync("eslint/bin/eslint.js", { basedir })
debug("FOUND '%s'", binPath)
return binPath
}
catch (err) {
const binPath = resolve.sync("eslint/bin/eslint.js", { basedir });

debug("FOUND '%s'", binPath);
return binPath;
} catch (err) {
if ((err && err.code) !== "MODULE_NOT_FOUND") {
throw err
throw err;
}
debug("NOT FOUND 'eslint/bin/eslint.js'")
return null
debug("NOT FOUND 'eslint/bin/eslint.js'");
return null;
}
}
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
"resolve": "^1.3.3"
},
"devDependencies": {
"eslint": "^4.10.0",
"eslint-config-mysticatea": "^12.0.0"
"eslint": "^4.19.1",
"eslint-config-eslint": "^4.0.0",
"eslint-plugin-node": "^6.0.1"
},
"repository": {
"type": "git",
Expand Down