Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(package): Add ESLint #1796

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.min.js
/components.js
/utopia.js
/vendor/**
ExE-Boss marked this conversation as resolved.
Show resolved Hide resolved
91 changes: 91 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"env": {
"browser": true,
"node": true,
},
"extends": "eslint:recommended",
"globals": {
"Prism": "readonly",
},
"parserOptions": {
"ecmaVersion": 5,
},
"root": true,
"rules": {
// "indent": [
// "error",
// "tab",
// {
// "SwitchCase": 1,
// "outerIIFEBody": 0,
// }
// ],
ExE-Boss marked this conversation as resolved.
Show resolved Hide resolved
"linebreak-style": [
"error",
"unix",
],
"no-console": "off",
"no-empty": "off",
ExE-Boss marked this conversation as resolved.
Show resolved Hide resolved
"no-inner-declarations": "off",
"no-mixed-spaces-and-tabs": "error",
"no-redeclare": "off",
ExE-Boss marked this conversation as resolved.
Show resolved Hide resolved
"no-sparse-arrays": "off",
"no-unused-vars": [
"warn",
{
"args": "none",
"argsIgnorePattern": "^_",
ExE-Boss marked this conversation as resolved.
Show resolved Hide resolved
"varsIgnorePattern": "^_",
ExE-Boss marked this conversation as resolved.
Show resolved Hide resolved
}
],
"no-useless-escape": "off",
// "quotes": [
// "warn",
// "single",
// {
// "avoidEscape": true,
// }
// ],
"semi": [
"error",
"always",
],
},
"overrides": [
{
"files": [
"gulpfile.js",
],
"env": {
"es6": true,
},
"parserOptions": {
"ecmaVersion": 2015,
}
},
{
"files": [
"code.js",
"download.js",
"examples.js",
"utopia.js",
ExE-Boss marked this conversation as resolved.
Show resolved Hide resolved
],
ExE-Boss marked this conversation as resolved.
Show resolved Hide resolved
"globals": {
"$": "readonly",
"$$": "readonly",
"$u": "readonly",
"Utopia": "readonly",
"Promise": "readonly",
"components": "readonly",
"setTheme": "readonly",
"PrefixFree": "readonly",
"StyleFix": "readonly",
},
"rules": {
"no-cond-assign": "off",
"no-mixed-spaces-and-tabs": "off",
"semi": "off",
ExE-Boss marked this conversation as resolved.
Show resolved Hide resolved
},
}
]
}
10 changes: 5 additions & 5 deletions components/prism-abap.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/prism-cil.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Prism.languages.cil = {
'number': /\b-?(?:0x[0-9a-fA-F]+|[0-9]+)(?:\.[0-9a-fA-F]+)?\b/i,

'punctuation': /[{}[\];(),:=]|IL_[0-9A-Za-z]+/
}
};
8 changes: 4 additions & 4 deletions components/prism-coffeescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

// Ignore comments starting with { to privilege string interpolation highlighting
var comment = /#(?!\{).+/,
interpolation = {
pattern: /#\{[^}]+\}/,
alias: 'variable'
};
interpolation = {
pattern: /#\{[^}]+\}/,
alias: 'variable'
};

Prism.languages.coffeescript = Prism.languages.extend('javascript', {
'comment': comment,
Expand Down
28 changes: 14 additions & 14 deletions components/prism-core.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global WorkerGlobalScope */
ExE-Boss marked this conversation as resolved.
Show resolved Hide resolved
var _self = (typeof window !== 'undefined')
? window // if in browser
: (
(typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
: ((typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
? self // if in worker
: {} // if in node js
);
Expand Down Expand Up @@ -152,7 +152,7 @@ var _ = {
callback.call(o, i, o[i], type || i);

var property = o[i],
propertyType = _.util.type(property);
propertyType = _.util.type(property);

if (propertyType === 'Object' && !visited[objId(property)]) {
visited[objId(property)] = true;
Expand Down Expand Up @@ -182,7 +182,7 @@ var _ = {

var elements = env.elements || container.querySelectorAll(env.selector);

for (var i=0, element; element = elements[i++];) {
for (var i=0, element; (element = elements[i++]);) {
_.highlightElement(element, async === true, env.callback);
}
},
Expand Down Expand Up @@ -231,7 +231,7 @@ var _ = {
_.hooks.run('after-highlight', env);
_.hooks.run('complete', env);
callback && callback.call(env.element);
}
};

_.hooks.run('before-sanity-check', env);

Expand Down Expand Up @@ -328,9 +328,9 @@ var _ = {
}

var from = match.index + (lookbehind ? match[1].length : 0),
to = match.index + match[0].length,
k = i,
p = pos;
to = match.index + match[0].length,
k = i,
p = pos;

for (var len = strarr.length; k < len && (p < to || (!strarr[k].type && !strarr[k - 1].greedy)); ++k) {
p += strarr[k].length;
Expand Down Expand Up @@ -370,10 +370,10 @@ var _ = {
}

var from = match.index + lookbehindLength,
match = match[0].slice(lookbehindLength),
to = from + match.length,
before = str.slice(0, from),
after = str.slice(to);
match = match[0].slice(lookbehindLength),
to = from + match.length,
before = str.slice(0, from),
after = str.slice(to);

var args = [i, delNum];

Expand Down Expand Up @@ -439,7 +439,7 @@ var _ = {
return;
}

for (var i=0, callback; callback = callbacks[i++];) {
for (var i=0, callback; (callback = callbacks[i++]);) {
callback(env);
}
}
Expand Down Expand Up @@ -549,5 +549,5 @@ if (typeof module !== 'undefined' && module.exports) {

// hack for components to work correctly in node.js
if (typeof global !== 'undefined') {
global.Prism = Prism;
global['Prism'] = Prism;
ExE-Boss marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 1 addition & 1 deletion components/prism-haml.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
},
rest: Prism.languages[filter.language]
}
}
};
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/prism-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {
'operator': /-[-=]?|\+[+=]?|!=?=?|<<?=?|>>?>?=?|=(?:==?|>)?|&[&=]?|\|[|=]?|\*\*?=?|\/=?|~|\^=?|%=?|\?|\.{3}/
});

Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|interface|extends|implements|instanceof|new)\s+)[\w.\\]+/
Prism.languages.javascript['class-name'][0].pattern = /(\b(?:class|interface|extends|implements|instanceof|new)\s+)[\w.\\]+/;

Prism.languages.insertBefore('javascript', 'keyword', {
'regex': {
Expand Down
2 changes: 1 addition & 1 deletion components/prism-json5.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function (Prism) {

var string = /("|')(?:\\(?:\r\n?|\n|.)|(?!\1)[^\\\r\n])*\1/
var string = /("|')(?:\\(?:\r\n?|\n|.)|(?!\1)[^\\\r\n])*\1/;

Prism.languages.json5 = Prism.languages.extend('json', {
'property': [
Expand Down
2 changes: 1 addition & 1 deletion components/prism-jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var walkTokens = function (tokens) {
openedTags[openedTags.length - 1].openedBraces--;

} else {
notTagNorBrace = true
notTagNorBrace = true;
}
}
if (notTagNorBrace || typeof token === 'string') {
Expand Down
12 changes: 6 additions & 6 deletions components/prism-latex.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
(function(Prism) {
var funcPattern = /\\(?:[^a-z()[\]]|[a-z*]+)/i,
insideEqu = {
'equation-command': {
pattern: funcPattern,
alias: 'regex'
}
};
insideEqu = {
'equation-command': {
pattern: funcPattern,
alias: 'regex'
}
};

Prism.languages.latex = {
'comment': /%.*/m,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-pug.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
},
rest: Prism.languages[filter.language]
}
}
};
}
}

Expand Down
6 changes: 3 additions & 3 deletions components/prism-regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
pattern: /\\[\\(){}[\]^$+*?|.]/,
alias: 'escape'
};
var escape = /\\(?:x[\da-fA-F]{2}|u[\da-fA-F]{4}|u\{[\da-fA-F]+\}|c[a-zA-Z]|0[0-7]{0,2}|[123][0-7]{2}|.)/
var charClass = /\\[wsd]|\.|\\p{[^{}]+}/i
var escape = /\\(?:x[\da-fA-F]{2}|u[\da-fA-F]{4}|u\{[\da-fA-F]+\}|c[a-zA-Z]|0[0-7]{0,2}|[123][0-7]{2}|.)/;
var charClass = /\\[wsd]|\.|\\p{[^{}]+}/i;

var rangeChar = '(?:[^\\\\-]|' + escape.source + ')';
var range = RegExp(rangeChar + '-' + rangeChar);
Expand Down Expand Up @@ -94,4 +94,4 @@
}
});

}(Prism))
}(Prism));
2 changes: 1 addition & 1 deletion components/prism-xquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
openedTags[openedTags.length - 1].openedBraces--;

} else if (token.type !== 'comment') {
notTagNorBrace = true
notTagNorBrace = true;
}
}
if (notTagNorBrace || typeof token === 'string') {
Expand Down
12 changes: 10 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { src, dest, series, parallel, watch } = require('gulp');

const eslint = require('gulp-eslint');
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');
const header = require('gulp-header');
Expand Down Expand Up @@ -61,6 +62,13 @@ function minifyJS() {
];
}

function lint(cb) {
return pump([
src(['**/*.js', '!node_modules/**'], { base: './' }),
eslint(),
eslint.format(),
], cb);
ExE-Boss marked this conversation as resolved.
Show resolved Hide resolved
}

function minifyComponents(cb) {
pump([src(paths.components), ...minifyJS(), rename({ suffix: '.min' }), dest('components')], cb);
Expand Down Expand Up @@ -191,7 +199,7 @@ function changelog(cb) {
const components = minifyComponents;
const plugins = series(languagePlugins, minifyPlugins);


exports.lint = lint;
exports.watch = watchComponentsAndPlugins;
exports.default = parallel(components, plugins, componentsJsonToJs, build);
exports.default = parallel(lint, components, plugins, componentsJsonToJs, build);
exports.changelog = changelog;
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
},
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^5.15.1",
ExE-Boss marked this conversation as resolved.
Show resolved Hide resolved
"gulp": "^4.0.0",
"gulp-concat": "^2.3.4",
"gulp-eslint": "^5.0.0",
"gulp-header": "^2.0.7",
"gulp-rename": "^1.2.0",
"gulp-replace": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
var getLanguagePath = function (lang) {
return config.languages_path +
'prism-' + lang
+ (config.use_minified ? '.min' : '') + '.js'
+ (config.use_minified ? '.min' : '') + '.js';
};

/**
Expand Down
2 changes: 1 addition & 1 deletion plugins/custom-class/prism-custom-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Prism.plugins.customClass = {
prefix: function prefix(string) {
options.prefixString = string;
}
}
};

Prism.hooks.add('wrap', function (env) {
if (!options.classMap && !options.prefixString) {
Expand Down
4 changes: 2 additions & 2 deletions plugins/jsonp-highlight/prism-jsonp-highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
*/
function getAdapter(adapter) {
if (typeof adapter === "function") {
for (var i = 0, item; item = adapters[i++];) {
for (var i = 0, item; (item = adapters[i++]);) {
if (item.adapter.valueOf() === adapter.valueOf()) {
return item.adapter;
}
}
}
else if (typeof adapter === "string") {
for (var i = 0, item; item = adapters[i++];) {
for (var i = 0, item; (item = adapters[i++]);) {
if (item.name === adapter) {
return item.adapter;
}
Expand Down
Loading