Skip to content

Commit 4d3189c

Browse files
authored
Fixes #3787 -- ESLint updates and linting cleanup (#3790)
* ESLint updates and linting cleanup * Exclude test files from some linting rules for now * Fix some TypeScript and build issues
1 parent a917965 commit 4d3189c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+449
-442
lines changed

packages/less/.eslintrc.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
module.exports = {
2+
'parser': '@typescript-eslint/parser',
3+
'extends': 'eslint:recommended',
4+
'parserOptions': {
5+
'ecmaVersion': 2018,
6+
'sourceType': 'module'
7+
},
8+
'plugins': ['@typescript-eslint'],
9+
'env': {
10+
'browser': true,
11+
'node': true,
12+
'mocha': true
13+
},
14+
'globals': {},
15+
'rules': {
16+
indent: ['error', 4, {
17+
SwitchCase: 1
18+
}],
19+
'no-empty': ['error', { 'allowEmptyCatch': true }],
20+
quotes: ['error', 'single', {
21+
avoidEscape: true
22+
}],
23+
/**
24+
* The codebase uses some while(true) statements.
25+
* Refactor to remove this rule.
26+
*/
27+
'no-constant-condition': 0,
28+
/**
29+
* Less combines assignments with conditionals sometimes
30+
*/
31+
'no-cond-assign': 0,
32+
/**
33+
* @todo - remove when some kind of code style (XO?) is added
34+
*/
35+
'no-multiple-empty-lines': 'error'
36+
},
37+
'overrides': [
38+
{
39+
files: ['*.ts'],
40+
extends: ['plugin:@typescript-eslint/recommended'],
41+
rules: {
42+
/**
43+
* Suppress until Less has better-defined types
44+
* @see https://github.com/less/less.js/discussions/3786
45+
*/
46+
'@typescript-eslint/no-explicit-any': 0
47+
}
48+
},
49+
{
50+
files: ['test/**/*.{js,ts}', 'benchmark/index.js'],
51+
/**
52+
* @todo - fix later
53+
*/
54+
rules: {
55+
'no-undef': 0,
56+
'no-useless-escape': 0,
57+
'no-unused-vars': 0,
58+
'no-redeclare': 0,
59+
'@typescript-eslint/no-unused-vars': 0
60+
}
61+
},
62+
]
63+
}

packages/less/.eslintrc.json

Lines changed: 0 additions & 71 deletions
This file was deleted.

packages/less/Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ module.exports = function(grunt) {
283283
"!test/less/errors/plugin/plugin-error.js"
284284
],
285285
options: {
286-
configFile: ".eslintrc.json",
286+
configFile: ".eslintrc.js",
287287
fix: true
288288
}
289289
},

packages/less/benchmark/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var path = require('path'),
22
fs = require('fs'),
3-
now = require("performance-now");
3+
now = require('performance-now');
44

55
var less = require('../.');
66
var file = path.join(__dirname, 'benchmark.less');
@@ -10,12 +10,12 @@ if (process.argv[2]) { file = path.join(process.cwd(), process.argv[2]) }
1010
fs.readFile(file, 'utf8', function (e, data) {
1111
var start, total;
1212

13-
console.log("Benchmarking...\n", path.basename(file) + " (" +
14-
parseInt(data.length / 1024) + " KB)", "");
13+
console.log('Benchmarking...\n', path.basename(file) + ' (' +
14+
parseInt(data.length / 1024) + ' KB)', '');
1515

1616
var renderBenchmark = []
17-
, parserBenchmark = []
18-
, evalBenchmark = [];
17+
, parserBenchmark = []
18+
, evalBenchmark = [];
1919

2020
var totalruns = 30;
2121
var ignoreruns = 5;
@@ -74,13 +74,13 @@ fs.readFile(file, 'utf8', function (e, data) {
7474
var variation = maxtime - mintime;
7575
var variationperc = (variation / avgtime) * 100;
7676

77-
console.log("Min. Time: " + Math.round(mintime) + " ms");
78-
console.log("Max. Time: " + Math.round(maxtime) + " ms");
79-
console.log("Total Average Time: " + Math.round(avgtime) + " ms (" +
77+
console.log('Min. Time: ' + Math.round(mintime) + ' ms');
78+
console.log('Max. Time: ' + Math.round(maxtime) + ' ms');
79+
console.log('Total Average Time: ' + Math.round(avgtime) + ' ms (' +
8080
parseInt(1000 / avgtime *
81-
data.length / 1024) + " KB\/s)");
82-
console.log("+/- " + Math.round(variationperc) + "%");
83-
console.log("");
81+
data.length / 1024) + ' KB\/s)');
82+
console.log('+/- ' + Math.round(variationperc) + '%');
83+
console.log('');
8484
}
8585

8686
analyze('Parsing', parserBenchmark);

packages/less/build/rollup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async function buildBrowser() {
4747
include: [/^.+\.min\.js$/],
4848
output: {
4949
comments: function(node, comment) {
50-
if (comment.type == "comment2") {
50+
if (comment.type == 'comment2') {
5151
// preserve banner
5252
return /@license/i.test(comment.value);
5353
}

packages/less/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@
3737
"scripts": {
3838
"test": "grunt test",
3939
"grunt": "grunt",
40+
"lint": "eslint '**/*.{ts,js}'",
41+
"lint:fix": "eslint '**/*.{ts,js}' --fix",
4042
"build": "npm-run-all clean compile",
4143
"clean": "shx rm -rf ./lib tsconfig.tsbuildinfo",
42-
"compile": "tsc -p tsconfig.json",
44+
"compile": "tsc -p tsconfig.build.json",
4345
"copy:root": "shx cp -rf ./dist ../../",
44-
"dev": "tsc -p tsconfig.json -w",
46+
"dev": "tsc -p tsconfig.build.json -w",
4547
"prepublishOnly": "grunt dist"
4648
},
4749
"optionalDependencies": {

packages/less/src/less-browser/bootstrap.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* used in the browser distributed version of less
44
* to kick-start less using the browser api
55
*/
6-
/* global window, document */
7-
86
import defaultOptions from '../less/default-options';
97
import addDefaultOptions from './add-default-options';
108
import root from './index';
@@ -13,7 +11,7 @@ const options = defaultOptions();
1311

1412
if (window.less) {
1513
for (const key in window.less) {
16-
if (window.less.hasOwnProperty(key)) {
14+
if (Object.prototype.hasOwnProperty.call(window.less, key)) {
1715
options[key] = window.less[key];
1816
}
1917
}

packages/less/src/less-browser/cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default (window, options, logger) => {
2929
let vars = cache && cache.getItem(`${path}:vars`);
3030

3131
modifyVars = modifyVars || {};
32-
vars = vars || "{}"; // if not set, treat as the JSON representation of an empty object
32+
vars = vars || '{}'; // if not set, treat as the JSON representation of an empty object
3333

3434
if (timestamp && webInfo.lastModified &&
3535
(new Date(webInfo.lastModified).valueOf() ===

packages/less/src/less-browser/error-reporting.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default (window, less, options) => {
1111
let content;
1212
const errors = [];
1313
const filename = e.filename || rootHref;
14-
const filenameNoPath = filename.match(/([^\/]+(\?.*)?)$/)[1];
14+
const filenameNoPath = filename.match(/([^/]+(\?.*)?)$/)[1];
1515

1616
elem.id = id;
1717
elem.className = 'less-error-message';
@@ -113,7 +113,7 @@ export default (window, less, options) => {
113113
}
114114
}
115115

116-
function removeErrorConsole(path) {
116+
function removeErrorConsole() {
117117
// no action
118118
}
119119

packages/less/src/less-browser/file-manager.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* global window, XMLHttpRequest */
2-
31
import AbstractFileManager from '../less/environment/abstract-file-manager.js';
42

53
let options;
@@ -66,7 +64,7 @@ FileManager.prototype = Object.assign(new AbstractFileManager(), {
6664
fileCache = {};
6765
},
6866

69-
loadFile(filename, currentDirectory, options, environment) {
67+
loadFile(filename, currentDirectory, options) {
7068
// TODO: Add prefix support like less-node?
7169
// What about multiple paths?
7270

0 commit comments

Comments
 (0)