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 12 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
/scripts/utopia.js
/scripts/vendor/**
109 changes: 109 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"env": {
"browser": true,
"commonjs": true,
},
"extends": "eslint:recommended",
"globals": {
"Prism": "readonly",
},
"parserOptions": {
"ecmaVersion": 5,
},
"root": true,
"rules": {
"comma-dangle": [
"warn",
"only-multiline",
],
"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",
}
],
"no-useless-escape": "off",
"semi": [
"error",
"always",
],
},
"overrides": [
{
"files": [
"components/*.js",
"gulpfile.js",
],
"rules": {
"quotes": [
"warn",
"single",
{
"avoidEscape": true,
}
],
},
},
{
"files": [
"components/prism-core.js",
"prism.js",
],
"globals": {
"WorkerGlobalScope": "readonly",
},
},
{
"files": [
"tests/**/*.js"
],
"env": {
"es6": true,
"node": true,
"mocha": true,
},
"parserOptions": {
"ecmaVersion": 2015,
},
},
{
"files": [
"gulpfile.js",
],
"env": {
"es6": true,
"node": true,
},
"parserOptions": {
"ecmaVersion": 2015,
},
},
{
"files": [
"scripts/**/*.js",
],
ExE-Boss marked this conversation as resolved.
Show resolved Hide resolved
"globals": {
"$": "readonly",
"$$": "readonly",
"$u": "readonly",
"Utopia": "readonly",
"Promise": "readonly",
"components": "readonly",
"setTheme": "readonly",
"saveAs": "readonly",
"PrefixFree": "readonly",
"StyleFix": "readonly",
},
}
]
}
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ before_script:
- npm install -g gulp
- gulp
- gulp premerge
script: npm test
script:
- gulp lint
- npm test
deploy:
provider: npm
email: [email protected]
Expand Down
16 changes: 8 additions & 8 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-aspnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Prism.languages.aspnet.tag.pattern = /<(?!%)\/?[^\s>\/]+(?:\s+[^\s>\/=]+(?:=(?:(
// match directives of attribute value foo="<% Bar %>"
Prism.languages.insertBefore('inside', 'punctuation', {
'directive tag': Prism.languages.aspnet['directive tag']
}, Prism.languages.aspnet.tag.inside["attr-value"]);
}, Prism.languages.aspnet.tag.inside['attr-value']);

Prism.languages.insertBefore('aspnet', 'comment', {
'asp comment': /<%--[\s\S]*?--%>/
Expand Down
24 changes: 12 additions & 12 deletions components/prism-autoit.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
Prism.languages.autoit = {
"comment": [
'comment': [
/;.*/,
{
// The multi-line comments delimiters can actually be commented out with ";"
pattern: /(^\s*)#(?:comments-start|cs)[\s\S]*?^\s*#(?:comments-end|ce)/m,
lookbehind: true
}
],
"url": {
'url': {
pattern: /(^\s*#include\s+)(?:<[^\r\n>]+>|"[^\r\n"]+")/m,
lookbehind: true
},
"string": {
'string': {
pattern: /(["'])(?:\1\1|(?!\1)[^\r\n])*\1/,
greedy: true,
inside: {
"variable": /([%$@])\w+\1/
'variable': /([%$@])\w+\1/
}
},
"directive": {
'directive': {
pattern: /(^\s*)#\w+/m,
lookbehind: true,
alias: 'keyword'
},
"function": /\b\w+(?=\()/,
'function': /\b\w+(?=\()/,
// Variables and macros
"variable": /[$@]\w+/,
"keyword": /\b(?:Case|Const|Continue(?:Case|Loop)|Default|Dim|Do|Else(?:If)?|End(?:Func|If|Select|Switch|With)|Enum|Exit(?:Loop)?|For|Func|Global|If|In|Local|Next|Null|ReDim|Select|Static|Step|Switch|Then|To|Until|Volatile|WEnd|While|With)\b/i,
"number": /\b(?:0x[\da-f]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?)\b/i,
"boolean": /\b(?:True|False)\b/i,
"operator": /<[=>]?|[-+*\/=&>]=?|[?^]|\b(?:And|Or|Not)\b/i,
"punctuation": /[\[\]().,:]/
'variable': /[$@]\w+/,
'keyword': /\b(?:Case|Const|Continue(?:Case|Loop)|Default|Dim|Do|Else(?:If)?|End(?:Func|If|Select|Switch|With)|Enum|Exit(?:Loop)?|For|Func|Global|If|In|Local|Next|Null|ReDim|Select|Static|Step|Switch|Then|To|Until|Volatile|WEnd|While|With)\b/i,
'number': /\b(?:0x[\da-f]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?)\b/i,
'boolean': /\b(?:True|False)\b/i,
'operator': /<[=>]?|[-+*\/=&>]=?|[?^]|\b(?:And|Or|Not)\b/i,
'punctuation': /[\[\]().,:]/
};
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
39 changes: 19 additions & 20 deletions components/prism-core.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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 +151,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 All @@ -178,11 +177,11 @@ var _ = {
selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
};

_.hooks.run("before-highlightall", env);
_.hooks.run('before-highlightall', env);

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 +230,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 @@ -288,7 +287,7 @@ var _ = {
}

var patterns = grammar[token];
patterns = (_.util.type(patterns) === "Array") ? patterns : [patterns];
patterns = (_.util.type(patterns) === 'Array') ? patterns : [patterns];

for (var j = 0; j < patterns.length; ++j) {
var pattern = patterns[j],
Expand All @@ -301,7 +300,7 @@ var _ = {
if (greedy && !pattern.pattern.global) {
// Without the global flag, lastIndex won't work
var flags = pattern.pattern.toString().match(/[imuy]*$/)[0];
pattern.pattern = RegExp(pattern.pattern.source, flags + "g");
pattern.pattern = RegExp(pattern.pattern.source, flags + 'g');
}

pattern = pattern.pattern || pattern;
Expand All @@ -328,9 +327,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 +369,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 +438,7 @@ var _ = {
return;
}

for (var i=0, callback; callback = callbacks[i++];) {
for (var i=0, callback; (callback = callbacks[i++]);) {
callback(env);
}
}
Expand All @@ -455,7 +454,7 @@ function Token(type, content, alias, matchedStr, greedy) {
this.content = content;
this.alias = alias;
// Copy of the full string this token was created from
this.length = (matchedStr || "").length|0;
this.length = (matchedStr || '').length|0;
this.greedy = !!greedy;
}

Expand Down Expand Up @@ -518,13 +517,13 @@ if (!_self.document) {
}

//Get current script and highlight
var script = document.currentScript || [].slice.call(document.getElementsByTagName("script")).pop();
var script = document.currentScript || [].slice.call(document.getElementsByTagName('script')).pop();

if (script) {
_.filename = script.src;

if (!_.manual && !script.hasAttribute('data-manual')) {
if(document.readyState !== "loading") {
if(document.readyState !== 'loading') {
if (window.requestAnimationFrame) {
window.requestAnimationFrame(_.highlightAll);
} else {
Expand All @@ -547,5 +546,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 @@ -22,7 +22,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
Loading