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

8.3.x
Alex Pott 2016-10-23 14:54:55 -07:00
parent 2cde5b67c6
commit 193aae3079
9 changed files with 30 additions and 19 deletions

View File

@ -6,3 +6,4 @@ libraries/**/*
sites/**/libraries/**/*
profiles/**/libraries/**/*
**/js_test_files/**/*
**/node_modules/**/*

View File

@ -1,3 +0,0 @@
{
"extends": "./core/.eslintrc"
}

3
.eslintrc.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "./core/.eslintrc.json"
}

4
core/.eslintignore Normal file
View File

@ -0,0 +1,4 @@
assets/vendor/**/*
modules/locale/tests/locale_test.js
node_modules/**/*
**/js_test_files/**/*

View File

@ -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],

View File

@ -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;

View File

@ -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": [

View File

@ -0,0 +1,5 @@
{
"rules": {
"strict": [2, "global"]
}
}

View File

@ -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);
});
})