From 193aae307933d0c734b4855ceb0240410ec9fb29 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Sun, 23 Oct 2016 14:54:55 -0700 Subject: [PATCH] Issue #2809343 by drpal, droplet, nod_: Add ESLint to package.json --- .eslintignore | 1 + .eslintrc | 3 --- .eslintrc.json | 3 +++ core/.eslintignore | 4 ++++ core/{.eslintrc => .eslintrc.json} | 2 +- core/misc/active-link.js | 2 +- core/package.json | 7 +++++-- core/scripts/js/.eslintrc.json | 5 +++++ core/scripts/js/babel-es6-watch.js | 22 ++++++++++------------ 9 files changed, 30 insertions(+), 19 deletions(-) delete mode 100644 .eslintrc create mode 100644 .eslintrc.json create mode 100644 core/.eslintignore rename core/{.eslintrc => .eslintrc.json} (98%) create mode 100644 core/scripts/js/.eslintrc.json diff --git a/.eslintignore b/.eslintignore index 961edb75337..de133ba4492 100644 --- a/.eslintignore +++ b/.eslintignore @@ -6,3 +6,4 @@ libraries/**/* sites/**/libraries/**/* profiles/**/libraries/**/* **/js_test_files/**/* +**/node_modules/**/* diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 9c0e3e698d0..00000000000 --- a/.eslintrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "./core/.eslintrc" -} diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000000..d4bbc920522 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "./core/.eslintrc.json" +} diff --git a/core/.eslintignore b/core/.eslintignore new file mode 100644 index 00000000000..a15282a9a4a --- /dev/null +++ b/core/.eslintignore @@ -0,0 +1,4 @@ +assets/vendor/**/* +modules/locale/tests/locale_test.js +node_modules/**/* +**/js_test_files/**/* diff --git a/core/.eslintrc b/core/.eslintrc.json similarity index 98% rename from core/.eslintrc rename to core/.eslintrc.json index 42dda02cd93..218d84f9372 100644 --- a/core/.eslintrc +++ b/core/.eslintrc.json @@ -82,7 +82,7 @@ "space-infix-ops": 2, "space-unary-ops": [2, { "words": true, "nonwords": false }], "spaced-comment": [2, "always"], - "strict": 2, + "strict": [2, "function"], "yoda": [2, "never"], // Warnings. "max-nested-callbacks": [1, 3], diff --git a/core/misc/active-link.js b/core/misc/active-link.js index 9cf55b43444..65037f75b80 100644 --- a/core/misc/active-link.js +++ b/core/misc/active-link.js @@ -26,7 +26,7 @@ // Start by finding all potentially active links. var path = drupalSettings.path; var queryString = JSON.stringify(path.currentQuery); - var querySelector = path.currentQuery ? "[data-drupal-link-query='" + queryString + "']" : ':not([data-drupal-link-query])'; + var querySelector = path.currentQuery ? "[data-eedrupal-link-query='" + queryString + "']" : ':not([data-drupal-link-query])'; var originalSelectors = ['[data-drupal-link-system-path="' + path.currentPath + '"]']; var selectors; diff --git a/core/package.json b/core/package.json index 8bf4e79c8c5..0c595be357a 100644 --- a/core/package.json +++ b/core/package.json @@ -5,12 +5,15 @@ "private": true, "scripts": { "build:js": "./scripts/js/babel-es6-compile.sh", - "watch:js": "node ./scripts/js/babel-es6-watch.js" + "watch:js": "node ./scripts/js/babel-es6-watch.js", + "lint:js": "eslint . || exit 0" }, "devDependencies": { "babel-cli": "6.16.0", + "babel-core": "6.17.0", "babel-preset-es2015": "6.16.0", - "chokidar": "1.6.0" + "chokidar": "1.6.0", + "eslint": "3.8.1" }, "babel": { "presets": [ diff --git a/core/scripts/js/.eslintrc.json b/core/scripts/js/.eslintrc.json new file mode 100644 index 00000000000..4152517e276 --- /dev/null +++ b/core/scripts/js/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "rules": { + "strict": [2, "global"] + } +} diff --git a/core/scripts/js/babel-es6-watch.js b/core/scripts/js/babel-es6-watch.js index 9262e9e6715..2bae2456ef4 100644 --- a/core/scripts/js/babel-es6-watch.js +++ b/core/scripts/js/babel-es6-watch.js @@ -15,13 +15,13 @@ const babel = require('babel-core'); const chokidar = require('chokidar'); // Logging human-readable timestamp. -const log = function (message) { +const log = function log(message) { // eslint-disable-next-line no-console console.log(`[${new Date().toTimeString().slice(0, 8)}] ${message}`); }; function addSourceMappingUrl(code, loc) { - return code + '\n\n//# sourceMappingURL=' + path.basename(loc); + return `${code}\n\n//# sourceMappingURL=${path.basename(loc)}`; } const fileMatch = './**/*.es6.js'; @@ -36,15 +36,13 @@ const babelOptions = { }; const changedOrAdded = (filePath) => { - babel.transformFile(filePath, babelOptions, function (err, result) { + babel.transformFile(filePath, babelOptions, (err, result) => { const fileName = filePath.slice(0, -7); - // we've requested for a sourcemap to be written to disk - let mapLoc = `${fileName}.js.map`; - result.code = addSourceMappingUrl(result.code, mapLoc); - fs.writeFileSync(mapLoc, JSON.stringify(result.map)); + const mapLoc = `${fileName}.js.map`; - fs.writeFileSync(`${fileName}.js`, result.code); + fs.writeFileSync(mapLoc, JSON.stringify(result.map)); + fs.writeFileSync(`${fileName}.js`, addSourceMappingUrl(result.code, mapLoc)); log(`'${filePath}' has been changed.`); }); @@ -52,19 +50,19 @@ const changedOrAdded = (filePath) => { const unlinkHandler = (err) => { if (err) { - return log(err); + log(err); } }; watcher .on('add', filePath => changedOrAdded(filePath)) .on('change', filePath => changedOrAdded(filePath)) - .on('unlink', filePath => { + .on('unlink', (filePath) => { const fileName = filePath.slice(0, -7); - fs.stat(`${fileName}.js`, function () { + fs.stat(`${fileName}.js`, () => { fs.unlink(`${fileName}.js`, unlinkHandler); }); - fs.stat(`${fileName}.js.map`, function () { + fs.stat(`${fileName}.js.map`, () => { fs.unlink(`${fileName}.js.map`, unlinkHandler); }); })