Commit 193aae30 authored by alexpott's avatar alexpott

Issue #2809343 by drpal, droplet, nod_: Add ESLint to package.json

parent 2cde5b67
...@@ -6,3 +6,4 @@ libraries/**/* ...@@ -6,3 +6,4 @@ libraries/**/*
sites/**/libraries/**/* sites/**/libraries/**/*
profiles/**/libraries/**/* profiles/**/libraries/**/*
**/js_test_files/**/* **/js_test_files/**/*
**/node_modules/**/*
{
"extends": "./core/.eslintrc"
}
{
"extends": "./core/.eslintrc.json"
}
assets/vendor/**/*
modules/locale/tests/locale_test.js
node_modules/**/*
**/js_test_files/**/*
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
"space-infix-ops": 2, "space-infix-ops": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }], "space-unary-ops": [2, { "words": true, "nonwords": false }],
"spaced-comment": [2, "always"], "spaced-comment": [2, "always"],
"strict": 2, "strict": [2, "function"],
"yoda": [2, "never"], "yoda": [2, "never"],
// Warnings. // Warnings.
"max-nested-callbacks": [1, 3], "max-nested-callbacks": [1, 3],
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
// Start by finding all potentially active links. // Start by finding all potentially active links.
var path = drupalSettings.path; var path = drupalSettings.path;
var queryString = JSON.stringify(path.currentQuery); 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 originalSelectors = ['[data-drupal-link-system-path="' + path.currentPath + '"]'];
var selectors; var selectors;
......
...@@ -5,12 +5,15 @@ ...@@ -5,12 +5,15 @@
"private": true, "private": true,
"scripts": { "scripts": {
"build:js": "./scripts/js/babel-es6-compile.sh", "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": { "devDependencies": {
"babel-cli": "6.16.0", "babel-cli": "6.16.0",
"babel-core": "6.17.0",
"babel-preset-es2015": "6.16.0", "babel-preset-es2015": "6.16.0",
"chokidar": "1.6.0" "chokidar": "1.6.0",
"eslint": "3.8.1"
}, },
"babel": { "babel": {
"presets": [ "presets": [
......
{
"rules": {
"strict": [2, "global"]
}
}
...@@ -15,13 +15,13 @@ const babel = require('babel-core'); ...@@ -15,13 +15,13 @@ const babel = require('babel-core');
const chokidar = require('chokidar'); const chokidar = require('chokidar');
// Logging human-readable timestamp. // Logging human-readable timestamp.
const log = function (message) { const log = function log(message) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log(`[${new Date().toTimeString().slice(0, 8)}] ${message}`); console.log(`[${new Date().toTimeString().slice(0, 8)}] ${message}`);
}; };
function addSourceMappingUrl(code, loc) { function addSourceMappingUrl(code, loc) {
return code + '\n\n//# sourceMappingURL=' + path.basename(loc); return `${code}\n\n//# sourceMappingURL=${path.basename(loc)}`;
} }
const fileMatch = './**/*.es6.js'; const fileMatch = './**/*.es6.js';
...@@ -36,15 +36,13 @@ const babelOptions = { ...@@ -36,15 +36,13 @@ const babelOptions = {
}; };
const changedOrAdded = (filePath) => { const changedOrAdded = (filePath) => {
babel.transformFile(filePath, babelOptions, function (err, result) { babel.transformFile(filePath, babelOptions, (err, result) => {
const fileName = filePath.slice(0, -7); const fileName = filePath.slice(0, -7);
// we've requested for a sourcemap to be written to disk // we've requested for a sourcemap to be written to disk
let mapLoc = `${fileName}.js.map`; const mapLoc = `${fileName}.js.map`;
result.code = addSourceMappingUrl(result.code, mapLoc);
fs.writeFileSync(mapLoc, JSON.stringify(result.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.`); log(`'${filePath}' has been changed.`);
}); });
...@@ -52,19 +50,19 @@ const changedOrAdded = (filePath) => { ...@@ -52,19 +50,19 @@ const changedOrAdded = (filePath) => {
const unlinkHandler = (err) => { const unlinkHandler = (err) => {
if (err) { if (err) {
return log(err); log(err);
} }
}; };
watcher watcher
.on('add', filePath => changedOrAdded(filePath)) .on('add', filePath => changedOrAdded(filePath))
.on('change', filePath => changedOrAdded(filePath)) .on('change', filePath => changedOrAdded(filePath))
.on('unlink', filePath => { .on('unlink', (filePath) => {
const fileName = filePath.slice(0, -7); const fileName = filePath.slice(0, -7);
fs.stat(`${fileName}.js`, function () { fs.stat(`${fileName}.js`, () => {
fs.unlink(`${fileName}.js`, unlinkHandler); fs.unlink(`${fileName}.js`, unlinkHandler);
}); });
fs.stat(`${fileName}.js.map`, function () { fs.stat(`${fileName}.js.map`, () => {
fs.unlink(`${fileName}.js.map`, unlinkHandler); fs.unlink(`${fileName}.js.map`, unlinkHandler);
}); });
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment