Skip to content

Commit

Permalink
Added ESLint with minimal config (#2831)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Mar 26, 2021
1 parent 7cd9e79 commit 772d42b
Show file tree
Hide file tree
Showing 38 changed files with 979 additions and 67 deletions.
122 changes: 122 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: 'eslint:recommended',
rules: {
// I turned this rule off because we use `hasOwnProperty` in a lot of places
// TODO: Think about re-enabling this rule
'no-prototype-builtins': 'off',
// TODO: Think about re-enabling this rule
'no-cond-assign': 'off',
// TODO: Think about re-enabling this rule
'no-inner-declarations': 'off',
// TODO: Think about re-enabling this rule
'no-sparse-arrays': 'off',

// turning off some regex rules
// these are supposed to protect against accidental use but we need those quite often
'no-control-regex': 'off',
'no-empty-character-class': 'off',
'no-useless-escape': 'off'
},
ignorePatterns: [
'*.min.js',
'vendor/',
'utopia.js',
'docs/',
'components.js',
'prism.js',
'node_modules'
],

overrides: [
{
// Languages and plugins
files: [
'components/*.js',
'plugins/*/prism-*.js'
],
excludedFiles: 'components/index.js',
env: {
browser: true,
node: true,
worker: true
},
globals: {
'Prism': true
}
},
{
// `loadLanguages` function for Node.js
files: 'components/index.js',
env: {
es6: true,
node: true
},
parserOptions: {
ecmaVersion: 6
},
globals: {
'Prism': true
}
},
{
// Gulp and Danger
files: 'dependencies.js',
env: {
browser: true,
node: true
}
},
{
// The scripts that run on our website
files: 'assets/*.js',
env: {
browser: true
},
globals: {
'components': true,
'getLoader': true,
'PrefixFree': true,
'Prism': true,
'Promise': true,
'saveAs': true,
'$': true,
'$$': true,
'$u': true
}
},
{
// Test files
files: 'tests/**',
env: {
es6: true,
mocha: true,
node: true
},
parserOptions: {
ecmaVersion: 2018
}
},
{
// Gulp and Danger
files: [
'gulpfile.js/**',
'dangerfile.js'
],
env: {
es6: true,
node: true
},
parserOptions: {
ecmaVersion: 2018
}
},
{
// This file
files: '.eslintrc.js',
env: {
node: true
}
},
]
};
13 changes: 13 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,16 @@ jobs:
git add --all && \
git diff-index --cached HEAD --stat --exit-code || \
(echo && echo "The above files changed because the build is not up to date." && echo "Please rebuild Prism." && exit 1)
lint:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x
- run: npm ci
- run: npm run lint
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ gulpfile.js
.editorconfig
.gitattributes
.travis.yml
.eslintrc.js
20 changes: 10 additions & 10 deletions assets/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ $$('[data-plugin-header]').forEach(function (element) {
});

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

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

$$('script', element).forEach(function (script) {
var after = script.nextSibling, parent = script.parentNode;
var parent = script.parentNode;
parent.removeChild(script);
document.head.appendChild(script);
});
}
catch (e) {}
catch (e) { /* noop */ }
}
});
});
Expand All @@ -43,9 +43,9 @@ $$('[data-src][data-type="text/html"]').forEach(function(element) {
var toc = document.createElement('ol');

$$('body > section > h1').forEach(function(h1) {
var section = h1.parentNode,
text = h1.textContent,
id = h1.id || section.id;
var section = h1.parentNode;
var text = h1.textContent;
var id = h1.id || section.id;

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

if(!style.width) {
// calc not supported
var header = $('header'),
footer = $('footer');
var header = $('header');
var footer = $('footer');

function calculatePadding() {
header.style.padding =
Expand Down
20 changes: 11 additions & 9 deletions assets/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ function toArray(value) {
var hstr = window.location.hash.match(/(?:languages|plugins)=[-+\w]+|themes=[-\w]+/g);
if (hstr) {
hstr.forEach(function(str) {
var kv = str.split('=', 2),
category = kv[0],
ids = kv[1].split('+');
var kv = str.split('=', 2);
var category = kv[0];
var ids = kv[1].split('+');
if (category !== 'meta' && category !== 'core' && components[category]) {
for (var id in components[category]) {
if (components[category][id].option) {
Expand All @@ -54,6 +54,7 @@ if (hstr) {
if (themeInput) {
themeInput.checked = true;
}
// eslint-disable-next-line no-undef
setTheme(ids[0]);
}
var makeDefault = function (id) {
Expand Down Expand Up @@ -314,8 +315,8 @@ function getFilesSizes() {
continue;
}

var distro = all[id].files[minified? 'minified' : 'dev'],
files = distro.paths;
var distro = all[id].files[minified? 'minified' : 'dev'];
var files = distro.paths;

files.forEach(function (filepath) {
var file = cache[filepath] = cache[filepath] || {};
Expand Down Expand Up @@ -380,8 +381,8 @@ function update(updatedCategory, updatedId){
if (cache[path]) {
var file = cache[path];

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

if (info.enabled) {

Expand All @@ -408,6 +409,7 @@ function update(updatedCategory, updatedId){
if (themeInput) {
themeInput.checked = true;
}
// eslint-disable-next-line no-undef
setTheme(updatedId);
}
}
Expand Down Expand Up @@ -581,8 +583,8 @@ function buildCode(promises) {
promises = finalPromises;

// build
var i = 0,
l = promises.length;
var i = 0;
var l = promises.length;
var code = {js: '', css: ''};
var errors = [];

Expand Down
4 changes: 2 additions & 2 deletions components/prism-abap.js

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

2 changes: 2 additions & 0 deletions components/prism-bsl.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-misleading-character-class */

// 1C:Enterprise
// https://github.com/Diversus23/
//
Expand Down
10 changes: 5 additions & 5 deletions components/prism-coffeescript.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
(function(Prism) {

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

Prism.languages.coffeescript = Prism.languages.extend('javascript', {
'comment': comment,
Expand Down
5 changes: 3 additions & 2 deletions components/prism-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ var _ = {
if (o.hasOwnProperty(i)) {
callback.call(o, i, o[i], type || i);

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

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

// eslint-disable-next-line no-redeclare
var from = match.index,
matchStr = match[0],
before = str.slice(0, from),
Expand Down
2 changes: 1 addition & 1 deletion components/prism-js-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
var interpolationExpression = token.content;

var placeholder;
while (code.indexOf(placeholder = getPlaceholder(placeholderCounter++, language)) !== -1) { }
while (code.indexOf(placeholder = getPlaceholder(placeholderCounter++, language)) !== -1) { /* noop */ }
placeholderMap[placeholder] = interpolationExpression;
return placeholder;
}
Expand Down
2 changes: 1 addition & 1 deletion components/prism-naniscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
}
}
return stack.length === 0;
};
}

/**
* @param {string | Token | (string | Token)[]} token
Expand Down
2 changes: 1 addition & 1 deletion components/prism-nsis.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-openqasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Prism.languages.openqasm = {
'class-name': /\b(?:angle|bit|bool|creg|fixed|float|int|length|qreg|qubit|stretch|uint)\b/,
'function': /\b(?:sin|cos|tan|exp|ln|sqrt|rotl|rotr|popcount)\b(?=\s*\()/,

'constant': /\b(?:pi|tau|euler)\b|[π𝜏ℇ]/,
'constant': /\b(?:pi|tau|euler)\b|π|𝜏|ℇ/,
'number': {
pattern: /(^|[^.\w$])(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?(?:dt|ns|us|µs|ms|s)?/i,
lookbehind: true
Expand Down
2 changes: 1 addition & 1 deletion components/prism-openqasm.min.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-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}
});

parser = Prism.languages.insertBefore('inside', 'punctuation', {
Prism.languages.insertBefore('inside', 'punctuation', {
'expression': parser.expression,
'keyword': parser.keyword,
'variable': parser.variable,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-parser.min.js

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

1 change: 1 addition & 0 deletions components/prism-pure.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
alias: 'builtin'
},
// Any combination of operator chars can be an operator
// eslint-disable-next-line no-misleading-character-class
'operator': /(?:[!"#$%&'*+,\-.\/:<=>?@\\^`|~\u00a1-\u00bf\u00d7-\u00f7\u20d0-\u2bff]|\b_+\b)+|\b(?:and|div|mod|not|or)\b/,
// FIXME: How can we prevent | and , to be highlighted as operator when they are used alone?
'punctuation': /[(){}\[\];,|]/
Expand Down

0 comments on commit 772d42b

Please sign in to comment.