Skip to content

Commit

Permalink
Add ESLInt and linting task to package
Browse files Browse the repository at this point in the history
  • Loading branch information
schoenkaft committed Sep 23, 2019
1 parent 72aebc5 commit b1afd91
Show file tree
Hide file tree
Showing 17 changed files with 108 additions and 50 deletions.
25 changes: 25 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"env": {
"es6": true,
},
"extends": "airbnb-base",
"plugins": [
"import",
],
"rules": {
"import/extensions": ["error", "always", { "js": "never", "mjs": "never" }],
"comma-dangle": ["error", "always-multiline"],
"quote-props": ["error", "consistent"],
"arrow-parens": "off",
"no-confusing-arrow": "off",
"no-nested-ternary": "off",
"implicit-arrow-linebreak": "off",
"arrow-body-style": "off",
"quotes": "off",
"import/order": "off",
"import/prefer-default-export": "off",
"no-script-url": "off",
"no-unused-vars": ["error", { "args": "none" }],
"object-curly-newline": "off",
}
}
2 changes: 2 additions & 0 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable import/no-dynamic-require,global-require */

import fs from 'fs';
import path from 'path';
import log from 'fancy-log';
Expand Down
25 changes: 10 additions & 15 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from 'fs';
import path from 'path';
import log from 'fancy-log';

let parsedConfig;

Expand All @@ -12,24 +11,20 @@ const getParsedConfig = () => {
return parsedConfig;
};

const convertDotStringToObject = (o, s) => {
s = s.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to properties
s = s.replace(/^\./, ''); // strip a leading dot
var a = s.split('.');
for (var i = 0, n = a.length; i < n; ++i) {
var k = a[i];
if (k in o) {
o = o[k];
} else {
return;
const convertDotStringToObject = (object, entryString) => {
// Convert indexes to properties, strip leading dot and create an array.
const entries = entryString.replace(/\[(\w+)\]/g, '.$1').replace(/^\./, '').split('.');
return entries.reduce((acc, entry) => {
if (acc && entry in acc) {
return acc[entry];
}
}
return o;
return acc;
}, object);
};

const config = {
get(entry) {
return convertDotStringToObject(getParsedConfig(), entry);
get(entryString) {
return convertDotStringToObject(getParsedConfig(), entryString);
},
};

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
],
"main": "gulpfile.babel.js",
"scripts": {
"lint": "eslint . --ext=.js,.mjs",
"test": "echo \"Not testing anything just yet.\" && exit 0"
},
"repository": {
Expand All @@ -37,9 +38,9 @@
"browser-sync": "^2.18.13",
"del": "^5.0.0",
"dotenv": "^8.0.0",
"eslint": "^6.1.0",
"eslint": "^6.4.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-import": "^2.18.2",
"fancy-log": "^1.3.2",
"gulp": "^4.0.0",
"gulp-better-rollup": "^4.0.1",
Expand Down
2 changes: 0 additions & 2 deletions tasks/browsersync.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import config from '../lib/config';

import browserSyncPackage from 'browser-sync';
import { task } from 'gulp';

Expand Down
4 changes: 2 additions & 2 deletions tasks/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export const copy = done => {
log(`Skipping 'copy' task`);
return done();
}
pump([
return pump([
src(config.get('tasks.copy'), {
base: config.get('paths.src'),
}),
dest(config.get('paths.dist'))
dest(config.get('paths.dist')),
], done);
};

Expand Down
3 changes: 1 addition & 2 deletions tasks/eslint.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import config from '../lib/config';
import { isDevelopment } from '../lib/env';

import log from 'fancy-log';
import fs from 'fs';
import path from 'path';
import gulpEsLint from 'gulp-eslint';
import { src, dest, task } from 'gulp';
import { src, task } from 'gulp';

const ESLINT_CONFIG = fs.existsSync('.eslintrc')
? '.eslintrc'
Expand Down
6 changes: 3 additions & 3 deletions tasks/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ export const icons = done => {
log(`Skipping 'icons' task`);
return done();
}
pump([
return pump([
src(config.get('tasks.icons.src')),
svgmin((file) => ({
plugins: [{
cleanupIDs: {
prefix: path.basename(file.relative, path.extname(file.relative)) + '-',
prefix: path.basename(file.relative, `${path.extname(file.relative)}-`),
minify: true,
}
},
},
{
removeViewBox: false,
Expand Down
8 changes: 4 additions & 4 deletions tasks/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ export const images = done => {
log(`Skipping 'images' task`);
return done();
}
pump([
return pump([
src(config.get('tasks.images.src')),
imagemin([
imagemin.jpegtran({
progressive: true
progressive: true,
}),
imagemin.svgo({
plugins: [
{ removeViewBox: false },
]
})
],
}),
]),
dest(config.get('tasks.images.dist')),
], done);
Expand Down
17 changes: 7 additions & 10 deletions tasks/javascript-vendor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import config from '../lib/config';

import log from 'fancy-log';
import merge from 'merge-stream';
import pump from 'pump';
import gulpif from 'gulp-if';
import concat from 'gulp-concat';
import terser from 'gulp-terser';
import { src, dest, task } from 'gulp';
Expand Down Expand Up @@ -31,15 +29,14 @@ export const jsvendor = done => {
},
}))
.pipe(dest(entry.dist));
} else {
return src(entry.src)
.pipe(terser({
compress: {
drop_console: true,
},
}))
.pipe(dest(entry.dist));
}
return src(entry.src)
.pipe(terser({
compress: {
drop_console: true,
},
}))
.pipe(dest(entry.dist));
}));
};

Expand Down
1 change: 0 additions & 1 deletion tasks/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import config from '../lib/config';
import { isDevelopment } from '../lib/env';

import log from 'fancy-log';
import fs from 'fs';
import merge from 'merge-stream';
import browserSync from 'browser-sync';
import sourcemaps from 'gulp-sourcemaps';
Expand Down
2 changes: 1 addition & 1 deletion tasks/modernizr.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const modernizr = done => {
log(`Skipping 'modernizr' task`);
return done();
}
pump([
return pump([
src([
config.get('tasks.sass.src') || '',
config.get('tasks.javascript.src') || '',
Expand Down
6 changes: 3 additions & 3 deletions tasks/revision.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const hashFiles = done => {
log(`Skipping 'revision:hash' task for development`);
return done();
}
pump([
return pump([
src([
...DEFAULTS,
...config.get('tasks.revision.files') || [],
Expand All @@ -53,7 +53,7 @@ const replaceCss = done => {
log(`Skipping 'revision:css' task for development`);
return done();
}
pump([
return pump([
src(`${config.get('tasks.sass.dist')}/**/*.css`),
revReplace({ manifest: src(MANIFEST_FULL_PATH) }),
dest(config.get('tasks.sass.dist')),
Expand All @@ -68,7 +68,7 @@ const replaceJs = done => {
log(`Skipping 'revision:javascript' task for development`);
return done();
}
pump([
return pump([
src(`${config.get('tasks.javascript.dist')}/**/*.js`),
revReplace({ manifest: src(MANIFEST_FULL_PATH) }),
dest(config.get('tasks.javascript.dist')),
Expand Down
2 changes: 1 addition & 1 deletion tasks/sass-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import log from 'fancy-log';
import fs from 'fs';
import path from 'path';
import gulpSassLint from 'gulp-sass-lint';
import { src, dest, task } from 'gulp';
import { src, task } from 'gulp';

const LINT_CONFIG = fs.existsSync('.sass-lint.yml')
? '.sass-lint.yml'
Expand Down
2 changes: 1 addition & 1 deletion tasks/sass.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const sass = done => {
log(`Skipping 'sass' task`);
return done();
}
pump([
return pump([
src(config.get('tasks.sass.main')),
sassGlob(),
gulpSass().on('error', error => {
Expand Down
1 change: 0 additions & 1 deletion tasks/watch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import config from '../lib/config';

import browserSyncPackage from 'browser-sync';
import { task, watch, parallel, series } from 'gulp';

import { browsersync } from './browsersync';
Expand Down
47 changes: 45 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2254,7 +2254,7 @@ eslint-module-utils@^2.4.0:
debug "^2.6.8"
pkg-dir "^2.0.0"

eslint-plugin-import@^2.7.0:
eslint-plugin-import@^2.18.2:
version "2.18.2"
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.18.2.tgz#02f1180b90b077b33d447a17a2326ceb400aceb6"
integrity sha512-5ohpsHAiUBRNaBWAF08izwUGlbrJoJJ+W9/TBwsGoR1MnlgfwMIKrFeSjWbt6moabiXW9xNvtFz+97KHRfI4HQ==
Expand Down Expand Up @@ -2330,7 +2330,7 @@ eslint@^2.7.0:
text-table "~0.2.0"
user-home "^2.0.0"

eslint@^6.0.0, eslint@^6.1.0:
eslint@^6.0.0:
version "6.2.2"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-6.2.2.tgz#03298280e7750d81fcd31431f3d333e43d93f24f"
integrity sha512-mf0elOkxHbdyGX1IJEUsNBzCDdyoUgljF3rRlgfyYh0pwGnreLc0jjD6ZuleOibjmnUWZLY2eXwSooeOgGJ2jw==
Expand Down Expand Up @@ -2373,6 +2373,49 @@ eslint@^6.0.0, eslint@^6.1.0:
text-table "^0.2.0"
v8-compile-cache "^2.0.3"

eslint@^6.4.0:
version "6.4.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-6.4.0.tgz#5aa9227c3fbe921982b2eda94ba0d7fae858611a"
integrity sha512-WTVEzK3lSFoXUovDHEbkJqCVPEPwbhCq4trDktNI6ygs7aO41d4cDT0JFAT5MivzZeVLWlg7vHL+bgrQv/t3vA==
dependencies:
"@babel/code-frame" "^7.0.0"
ajv "^6.10.0"
chalk "^2.1.0"
cross-spawn "^6.0.5"
debug "^4.0.1"
doctrine "^3.0.0"
eslint-scope "^5.0.0"
eslint-utils "^1.4.2"
eslint-visitor-keys "^1.1.0"
espree "^6.1.1"
esquery "^1.0.1"
esutils "^2.0.2"
file-entry-cache "^5.0.1"
functional-red-black-tree "^1.0.1"
glob-parent "^5.0.0"
globals "^11.7.0"
ignore "^4.0.6"
import-fresh "^3.0.0"
imurmurhash "^0.1.4"
inquirer "^6.4.1"
is-glob "^4.0.0"
js-yaml "^3.13.1"
json-stable-stringify-without-jsonify "^1.0.1"
levn "^0.3.0"
lodash "^4.17.14"
minimatch "^3.0.4"
mkdirp "^0.5.1"
natural-compare "^1.4.0"
optionator "^0.8.2"
progress "^2.0.0"
regexpp "^2.0.1"
semver "^6.1.2"
strip-ansi "^5.2.0"
strip-json-comments "^3.0.1"
table "^5.2.3"
text-table "^0.2.0"
v8-compile-cache "^2.0.3"

espree@^3.1.6:
version "3.5.4"
resolved "https://registry.yarnpkg.com/espree/-/espree-3.5.4.tgz#b0f447187c8a8bed944b815a660bddf5deb5d1a7"
Expand Down

0 comments on commit b1afd91

Please sign in to comment.