Skip to content

Commit

Permalink
refactor(eslint): added eslint-standard
Browse files Browse the repository at this point in the history
  • Loading branch information
ritz078 committed Feb 23, 2017
1 parent 231479f commit b64ed1a
Show file tree
Hide file tree
Showing 22 changed files with 504 additions and 519 deletions.
30 changes: 5 additions & 25 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
{
"env": {
"node": true,
"es6": true,
"browser": true
},
"parser": "babel-eslint",
"extends": "eslint:recommended",
"extends": "standard",
"rules": {
"no-multi-spaces": 0,
"key-spacing": 0,
"no-return-assign": 0,
"consistent-return": 0,
"no-shadow": 0,
"comma-dangle": 0,
"no-use-before-define": 0,
"no-empty": 0,
"new-parens": 0,
"no-cond-assign": 0,
"no-fallthrough": 0,
"new-cap": 0,
"no-loop-func": 0,
"no-unreachable": 0,
"no-labels": 0,
"no-process-exit": 0,
"camelcase": 0,
"no-console": 0
"one-var": "off",
"no-tabs": "off",
"no-useless-escape": "off",
"no-new-func": "off"
}
}
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
"cssnano": "^3.4.0",
"cz-conventional-changelog": "^1.1.6",
"es6-promise": "^3.0.2",
"eslint": "^2.5.1",
"eslint": "^3.16.1",
"eslint-config-standard": "^6.2.1",
"eslint-plugin-promise": "^3.4.2",
"eslint-plugin-standard": "^2.0.1",
"fetch-jsonp": "^1.0.0",
"grunt": "^0.4.5",
"grunt-bump": "^0.7.0",
Expand Down Expand Up @@ -87,6 +90,8 @@
},
"scripts": {
"commit": "git-cz",
"lint": "eslint src/js/**/*.js",
"lintfix": "eslint --fix src/js/**/*.js",
"test": "ava test/**/*.test.js --require babel-register"
},
"config": {
Expand Down
10 changes: 5 additions & 5 deletions src/js/helpers/applyPlyr.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* @return {null}
*/
export default function (options) {
if (options.plyr) {
if (!options.plugins.plyr) throw new ReferenceError("You have enabled plyr but you haven't loaded the library.Find it at https://plyr.io/");
let plyr = options.plugins.plyr;
plyr.setup('.ejs-plyr', options.plyrOptions);
}
if (options.plyr) {
if (!options.plugins.plyr) throw new ReferenceError("You have enabled plyr but you haven't loaded the library.Find it at https://plyr.io/")
let plyr = options.plugins.plyr
plyr.setup('.ejs-plyr', options.plyrOptions)
}
}
22 changes: 11 additions & 11 deletions src/js/helpers/applyVideoJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* @param {object} options Options object
* @return {null}
*/
export default function applyVideoJS(options) {
options.videojsOptions.width = options.videoWidth;
options.videojsOptions.height = options.videoHeight;
if (options.videoJS) {
if (!options.plugins.videojs) throw new ReferenceError("You have enabled videojs but you haven't loaded the library.Find it at http://videojs.com/");
let VideoJS = options.plugins.videojs;
let elements = options.input.getElementsByClassName('ejs-video-js');
for (let i = 0; i < elements.length; i++) {
VideoJS(elements[i], options.videojsOptions, () => options.videojsCallback());
}
}
export default function applyVideoJS (options) {
options.videojsOptions.width = options.videoWidth
options.videojsOptions.height = options.videoHeight
if (options.videoJS) {
if (!options.plugins.videojs) throw new ReferenceError("You have enabled videojs but you haven't loaded the library.Find it at http://videojs.com/")
let VideoJS = options.plugins.videojs
let elements = options.input.getElementsByClassName('ejs-video-js')
for (let i = 0; i < elements.length; i++) {
VideoJS(elements[i], options.videojsOptions, () => options.videojsCallback())
}
}
}
126 changes: 65 additions & 61 deletions src/js/helpers/asyncEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import { matches, ifInline } from '../modules/utils'
* @param {object} match object containing info of matching string
* @return {Promise} resolves to the text
*/
function getInlineData(_, urlToText, match) {
let url = (_.options.link ? match[0].slice(0, -4) : match[0]) || match[1];
if (_.options.served.indexOf(url) >= 0) return Promise.resolve(null);
function getInlineData (_, urlToText, match) {
let url = (_.options.link ? match[0].slice(0, -4) : match[0]) || match[1]
if (_.options.served.indexOf(url) >= 0) return Promise.resolve(null)

return new Promise((resolve) => {
urlToText(_, match, url).then((text) => {
if (!text) return resolve();
_.options.served.push(url);
resolve(text);
})
})
return new Promise((resolve) => {
urlToText(_, match, url).then((text) => {
if (!text) return resolve()
_.options.served.push(url)
resolve(text)
})
})
}

/**
Expand All @@ -27,46 +27,48 @@ function getInlineData(_, urlToText, match) {
* @param urlToText
* @returns Promise
*/
function inlineAsyncEmbed(_, urlToText) {
let regexInline = _.options.link ? new RegExp(`([^>]*${_.regex.source})<\/a>`, 'gi') : new RegExp(`([^\\s]*${_.regex.source})`, 'gi');
let match, promises = [];
function inlineAsyncEmbed (_, urlToText) {
let regexInline = _.options.link ? new RegExp(`([^>]*${_.regex.source})<\/a>`, 'gi') : new RegExp(`([^\\s]*${_.regex.source})`, 'gi')
let match, promises = []

while ((match = matches(regexInline, _.output)) !== null)
promises.push(getInlineData(_, urlToText, match));
while ((match = matches(regexInline, _.output)) !== null) {
promises.push(getInlineData(_, urlToText, match))
}

return new Promise((resolve) => {
if (promises.length)
Promise.all(promises).then((data) => {
let i = 0;
_.output = _.output.replace(regexInline, (matched) => {
if (_.options.link)
return !_.options.inlineText ? data[i++] + '</a>' : matched + data[i++];
else
return !_.options.inlineText ? data[i++] : matched + data[i++];
});
resolve(_.output)
});
else
resolve(_.output)
})
return new Promise((resolve) => {
if (promises.length) {
Promise.all(promises).then((data) => {
let i = 0
_.output = _.output.replace(regexInline, (matched) => {
if (_.options.link) {
return !_.options.inlineText ? data[i++] + '</a>' : matched + data[i++]
} else {
return !_.options.inlineText ? data[i++] : matched + data[i++]
}
})
resolve(_.output)
})
} else {
resolve(_.output)
}
})
}

function getNormalData (_, urlToText, match) {
let url = match[0]
if (_.options.served.indexOf(url) >= 0) return

function getNormalData(_, urlToText, match) {
let url = match[0];
if (_.options.served.indexOf(url) >= 0) return;

return new Promise((resolve) => {
urlToText(_, match, url, true).then(function (text) {
if (!text) resolve();
_.options.served.push(url);
_.embeds.push({
text : text,
index: match.index
});
resolve()
})
})
return new Promise((resolve) => {
urlToText(_, match, url, true).then(function (text) {
if (!text) resolve()
_.options.served.push(url)
_.embeds.push({
text: text,
index: match.index
})
resolve()
})
})
}

/**
Expand All @@ -75,22 +77,24 @@ function getNormalData(_, urlToText, match) {
* @param {function} urlToText
* @return {Promise}
*/
function normalAsyncEmbed(_, urlToText) {
let match, promises = [];
while ((match = matches(_.regex, _.input)) !== null)
promises.push(getNormalData(_, urlToText, match));
return new Promise(function (resolve) {
Promise.all(promises).then(function () {
resolve(_.embeds)
});
})
function normalAsyncEmbed (_, urlToText) {
let match, promises = []
while ((match = matches(_.regex, _.input)) !== null) {
promises.push(getNormalData(_, urlToText, match))
}
return new Promise(function (resolve) {
Promise.all(promises).then(function () {
resolve(_.embeds)
})
})
}

export default function asyncEmbed(_, urlToText) {
return new Promise(function (resolve) {
if (ifInline(_.options, _.service))
inlineAsyncEmbed(_, urlToText).then((output) => resolve([output, _.embeds]));
else
normalAsyncEmbed(_, urlToText).then((embeds) => resolve([_.output, embeds]))
})
export default function asyncEmbed (_, urlToText) {
return new Promise(function (resolve) {
if (ifInline(_.options, _.service)) {
inlineAsyncEmbed(_, urlToText).then((output) => resolve([output, _.embeds]))
} else {
normalAsyncEmbed(_, urlToText).then((embeds) => resolve([_.output, embeds]))
}
})
}
4 changes: 2 additions & 2 deletions src/js/helpers/baseEmbed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ifEmbed } from '../modules/utils'
import base from '../modules/base'

export default function baseEmbed(input, output, embeds, options, regex, service, flag){
return ifEmbed(options, service) || (ifEmbed(options, service) && flag) ? base(input, output, embeds, options, regex, service) : [output, embeds]
export default function baseEmbed (input, output, embeds, options, regex, service, flag) {
return ifEmbed(options, service) || (ifEmbed(options, service) && flag) ? base(input, output, embeds, options, regex, service) : [output, embeds]
}
8 changes: 4 additions & 4 deletions src/js/helpers/destroyVideos.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* @return {null}
*/
export default function (className) {
const classes = document.getElementsByClassName(className);
for (let i = 0; i < classes.length; i++) {
classes[i].onclick = null
}
const classes = document.getElementsByClassName(className)
for (let i = 0; i < classes.length; i++) {
classes[i].onclick = null
}
}
62 changes: 31 additions & 31 deletions src/js/helpers/embed.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import { ifInline, matches } from '../modules/utils'

function inlineEmbed(_){
let regexInline = _.options.link ? new RegExp(`([^>]*${_.regex.source})<\/a>`, 'gm') : new RegExp(`([^\\s]*${_.regex.source})`, 'gm');
_.output = _.output.replace(regexInline, function(match) {
let url = _.options.link ? match.slice(0, -4) : match;
if (_.options.served.indexOf(url) === -1) {
_.options.served.push(url);
if (_.options.link) {
return !_.options.inlineText ? _.template(match.slice(0, -4)) + '</a>' : match + _.template(match.slice(0, -4))
} else {
return !_.options.inlineText ? _.template(match) : match + _.template(match)
}
} else {
return match; //TODO : check whether this should be `match`
}
});
return [_.output, _.embeds];
function inlineEmbed (_) {
let regexInline = _.options.link ? new RegExp(`([^>]*${_.regex.source})<\/a>`, 'gm') : new RegExp(`([^\\s]*${_.regex.source})`, 'gm')
_.output = _.output.replace(regexInline, function (match) {
let url = _.options.link ? match.slice(0, -4) : match
if (_.options.served.indexOf(url) === -1) {
_.options.served.push(url)
if (_.options.link) {
return !_.options.inlineText ? _.template(match.slice(0, -4)) + '</a>' : match + _.template(match.slice(0, -4))
} else {
return !_.options.inlineText ? _.template(match) : match + _.template(match)
}
} else {
return match // TODO : check whether this should be `match`
}
})
return [_.output, _.embeds]
}

function normalEmbed(_){
let match;
while ((match = matches(_.regex, _.input)) !== null) {
let url = match[0];
if (!(_.options.served.indexOf(url) === -1) || (_.options.served.length && _.options.singleEmbed)) continue;
_.options.served.push(url);
let text = _.template(url);
_.embeds.push({
text : text,
index: match.index
})
}
return [_.output, _.embeds];
function normalEmbed (_) {
let match
while ((match = matches(_.regex, _.input)) !== null) {
let url = match[0]
if (!(_.options.served.indexOf(url) === -1) || (_.options.served.length && _.options.singleEmbed)) continue
_.options.served.push(url)
let text = _.template(url)
_.embeds.push({
text: text,
index: match.index
})
}
return [_.output, _.embeds]
}

export default function embed(_){
return (ifInline(_.options, _.service)) ? inlineEmbed(_) : normalEmbed(_)
export default function embed (_) {
return (ifInline(_.options, _.service)) ? inlineEmbed(_) : normalEmbed(_)
}
10 changes: 5 additions & 5 deletions src/js/helpers/getDetailsTemplate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default function (data, fullData, embedUrl, options) {
if (data.host === 'vimeo') {
return options.template.detailsVimeo(data, fullData, embedUrl, options)
} else if (data.host === 'youtube') {
return options.template.detailsYoutube(data, fullData, embedUrl, options)
}
if (data.host === 'vimeo') {
return options.template.detailsVimeo(data, fullData, embedUrl, options)
} else if (data.host === 'youtube') {
return options.template.detailsYoutube(data, fullData, embedUrl, options)
}
}
17 changes: 8 additions & 9 deletions src/js/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import playVideo from './playVideo'
import playVideo from './playVideo'
import getDetailsTemplate from './getDetailsTemplate'
import applyPlyr from './applyPlyr'
import applyVideoJS from './applyVideoJS';
import destroyVideos from './destroyVideos'
import embed from './embed'
import template from './template'
import baseEmbed from './baseEmbed'
import asyncEmbed from './asyncEmbed'

import applyPlyr from './applyPlyr'
import applyVideoJS from './applyVideoJS'
import destroyVideos from './destroyVideos'
import embed from './embed'
import template from './template'
import baseEmbed from './baseEmbed'
import asyncEmbed from './asyncEmbed'

export {playVideo, getDetailsTemplate, applyPlyr, applyVideoJS, destroyVideos, embed, template, baseEmbed, asyncEmbed}
Loading

0 comments on commit b64ed1a

Please sign in to comment.