Issue #2809343 by drpal, droplet, nod_: Add ESLint to package.json
parent
2cde5b67c6
commit
193aae3079
|
@ -6,3 +6,4 @@ libraries/**/*
|
||||||
sites/**/libraries/**/*
|
sites/**/libraries/**/*
|
||||||
profiles/**/libraries/**/*
|
profiles/**/libraries/**/*
|
||||||
**/js_test_files/**/*
|
**/js_test_files/**/*
|
||||||
|
**/node_modules/**/*
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"extends": "./core/.eslintrc.json"
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
assets/vendor/**/*
|
||||||
|
modules/locale/tests/locale_test.js
|
||||||
|
node_modules/**/*
|
||||||
|
**/js_test_files/**/*
|
|
@ -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 @@
|
||||||
// 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 @@
|
||||||
"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": [
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"rules": {
|
||||||
|
"strict": [2, "global"]
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 = {
|
||||||
};
|
};
|
||||||
|
|
||||||
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) => {
|
||||||
|
|
||||||
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);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue