Skip to content

Commit 772d42b

Browse files
Added ESLint with minimal config (#2831)
1 parent 7cd9e79 commit 772d42b

38 files changed

+979
-67
lines changed

.eslintrc.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/** @type {import('eslint').Linter.Config} */
2+
module.exports = {
3+
extends: 'eslint:recommended',
4+
rules: {
5+
// I turned this rule off because we use `hasOwnProperty` in a lot of places
6+
// TODO: Think about re-enabling this rule
7+
'no-prototype-builtins': 'off',
8+
// TODO: Think about re-enabling this rule
9+
'no-cond-assign': 'off',
10+
// TODO: Think about re-enabling this rule
11+
'no-inner-declarations': 'off',
12+
// TODO: Think about re-enabling this rule
13+
'no-sparse-arrays': 'off',
14+
15+
// turning off some regex rules
16+
// these are supposed to protect against accidental use but we need those quite often
17+
'no-control-regex': 'off',
18+
'no-empty-character-class': 'off',
19+
'no-useless-escape': 'off'
20+
},
21+
ignorePatterns: [
22+
'*.min.js',
23+
'vendor/',
24+
'utopia.js',
25+
'docs/',
26+
'components.js',
27+
'prism.js',
28+
'node_modules'
29+
],
30+
31+
overrides: [
32+
{
33+
// Languages and plugins
34+
files: [
35+
'components/*.js',
36+
'plugins/*/prism-*.js'
37+
],
38+
excludedFiles: 'components/index.js',
39+
env: {
40+
browser: true,
41+
node: true,
42+
worker: true
43+
},
44+
globals: {
45+
'Prism': true
46+
}
47+
},
48+
{
49+
// `loadLanguages` function for Node.js
50+
files: 'components/index.js',
51+
env: {
52+
es6: true,
53+
node: true
54+
},
55+
parserOptions: {
56+
ecmaVersion: 6
57+
},
58+
globals: {
59+
'Prism': true
60+
}
61+
},
62+
{
63+
// Gulp and Danger
64+
files: 'dependencies.js',
65+
env: {
66+
browser: true,
67+
node: true
68+
}
69+
},
70+
{
71+
// The scripts that run on our website
72+
files: 'assets/*.js',
73+
env: {
74+
browser: true
75+
},
76+
globals: {
77+
'components': true,
78+
'getLoader': true,
79+
'PrefixFree': true,
80+
'Prism': true,
81+
'Promise': true,
82+
'saveAs': true,
83+
'$': true,
84+
'$$': true,
85+
'$u': true
86+
}
87+
},
88+
{
89+
// Test files
90+
files: 'tests/**',
91+
env: {
92+
es6: true,
93+
mocha: true,
94+
node: true
95+
},
96+
parserOptions: {
97+
ecmaVersion: 2018
98+
}
99+
},
100+
{
101+
// Gulp and Danger
102+
files: [
103+
'gulpfile.js/**',
104+
'dangerfile.js'
105+
],
106+
env: {
107+
es6: true,
108+
node: true
109+
},
110+
parserOptions: {
111+
ecmaVersion: 2018
112+
}
113+
},
114+
{
115+
// This file
116+
files: '.eslintrc.js',
117+
env: {
118+
node: true
119+
}
120+
},
121+
]
122+
};

.github/workflows/test.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,16 @@ jobs:
4444
git add --all && \
4545
git diff-index --cached HEAD --stat --exit-code || \
4646
(echo && echo "The above files changed because the build is not up to date." && echo "Please rebuild Prism." && exit 1)
47+
48+
lint:
49+
50+
runs-on: ubuntu-latest
51+
52+
steps:
53+
- uses: actions/checkout@v2
54+
- name: Use Node.js 14.x
55+
uses: actions/setup-node@v1
56+
with:
57+
node-version: 14.x
58+
- run: npm ci
59+
- run: npm run lint

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ gulpfile.js
1919
.editorconfig
2020
.gitattributes
2121
.travis.yml
22+
.eslintrc.js

assets/code.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ $$('[data-plugin-header]').forEach(function (element) {
1111
});
1212

1313
$$('[data-src][data-type="text/html"]').forEach(function(element) {
14-
var src = element.getAttribute('data-src'),
15-
html = element.getAttribute('data-type') === 'text/html',
16-
contentProperty = html ? 'innerHTML' : 'textContent';
14+
var src = element.getAttribute('data-src');
15+
var html = element.getAttribute('data-type') === 'text/html';
16+
var contentProperty = html ? 'innerHTML' : 'textContent';
1717

1818
$u.xhr({
1919
url: src,
@@ -24,12 +24,12 @@ $$('[data-src][data-type="text/html"]').forEach(function(element) {
2424
// Run JS
2525

2626
$$('script', element).forEach(function (script) {
27-
var after = script.nextSibling, parent = script.parentNode;
27+
var parent = script.parentNode;
2828
parent.removeChild(script);
2929
document.head.appendChild(script);
3030
});
3131
}
32-
catch (e) {}
32+
catch (e) { /* noop */ }
3333
}
3434
});
3535
});
@@ -43,9 +43,9 @@ $$('[data-src][data-type="text/html"]').forEach(function(element) {
4343
var toc = document.createElement('ol');
4444

4545
$$('body > section > h1').forEach(function(h1) {
46-
var section = h1.parentNode,
47-
text = h1.textContent,
48-
id = h1.id || section.id;
46+
var section = h1.parentNode;
47+
var text = h1.textContent;
48+
var id = h1.id || section.id;
4949

5050
// Assign id if one does not exist
5151
if (!id) {
@@ -128,8 +128,8 @@ if (toc.children.length > 0) {
128128

129129
if(!style.width) {
130130
// calc not supported
131-
var header = $('header'),
132-
footer = $('footer');
131+
var header = $('header');
132+
var footer = $('footer');
133133

134134
function calculatePadding() {
135135
header.style.padding =

assets/download.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ function toArray(value) {
4040
var hstr = window.location.hash.match(/(?:languages|plugins)=[-+\w]+|themes=[-\w]+/g);
4141
if (hstr) {
4242
hstr.forEach(function(str) {
43-
var kv = str.split('=', 2),
44-
category = kv[0],
45-
ids = kv[1].split('+');
43+
var kv = str.split('=', 2);
44+
var category = kv[0];
45+
var ids = kv[1].split('+');
4646
if (category !== 'meta' && category !== 'core' && components[category]) {
4747
for (var id in components[category]) {
4848
if (components[category][id].option) {
@@ -54,6 +54,7 @@ if (hstr) {
5454
if (themeInput) {
5555
themeInput.checked = true;
5656
}
57+
// eslint-disable-next-line no-undef
5758
setTheme(ids[0]);
5859
}
5960
var makeDefault = function (id) {
@@ -314,8 +315,8 @@ function getFilesSizes() {
314315
continue;
315316
}
316317

317-
var distro = all[id].files[minified? 'minified' : 'dev'],
318-
files = distro.paths;
318+
var distro = all[id].files[minified? 'minified' : 'dev'];
319+
var files = distro.paths;
319320

320321
files.forEach(function (filepath) {
321322
var file = cache[filepath] = cache[filepath] || {};
@@ -380,8 +381,8 @@ function update(updatedCategory, updatedId){
380381
if (cache[path]) {
381382
var file = cache[path];
382383

383-
var type = path.match(/\.(\w+)$/)[1],
384-
size = file.size || 0;
384+
var type = path.match(/\.(\w+)$/)[1];
385+
var size = file.size || 0;
385386

386387
if (info.enabled) {
387388

@@ -408,6 +409,7 @@ function update(updatedCategory, updatedId){
408409
if (themeInput) {
409410
themeInput.checked = true;
410411
}
412+
// eslint-disable-next-line no-undef
411413
setTheme(updatedId);
412414
}
413415
}
@@ -581,8 +583,8 @@ function buildCode(promises) {
581583
promises = finalPromises;
582584

583585
// build
584-
var i = 0,
585-
l = promises.length;
586+
var i = 0;
587+
var l = promises.length;
586588
var code = {js: '', css: ''};
587589
var errors = [];
588590

components/prism-abap.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/prism-bsl.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable no-misleading-character-class */
2+
13
// 1C:Enterprise
24
// https://github.com/Diversus23/
35
//

components/prism-coffeescript.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
(function(Prism) {
22

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

1010
Prism.languages.coffeescript = Prism.languages.extend('javascript', {
1111
'comment': comment,

components/prism-core.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ var _ = {
426426
if (o.hasOwnProperty(i)) {
427427
callback.call(o, i, o[i], type || i);
428428

429-
var property = o[i],
430-
propertyType = _.util.type(property);
429+
var property = o[i];
430+
var propertyType = _.util.type(property);
431431

432432
if (propertyType === 'Object' && !visited[objId(property)]) {
433433
visited[objId(property)] = true;
@@ -972,6 +972,7 @@ function matchGrammar(text, tokenList, grammar, startNode, startPos, rematch) {
972972
}
973973
}
974974

975+
// eslint-disable-next-line no-redeclare
975976
var from = match.index,
976977
matchStr = match[0],
977978
before = str.slice(0, from),

components/prism-js-templates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
var interpolationExpression = token.content;
171171

172172
var placeholder;
173-
while (code.indexOf(placeholder = getPlaceholder(placeholderCounter++, language)) !== -1) { }
173+
while (code.indexOf(placeholder = getPlaceholder(placeholderCounter++, language)) !== -1) { /* noop */ }
174174
placeholderMap[placeholder] = interpolationExpression;
175175
return placeholder;
176176
}

0 commit comments

Comments
 (0)