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

Fixes #3787 -- ESLint updates and linting cleanup #3790

Merged
merged 4 commits into from
Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
63 changes: 63 additions & 0 deletions packages/less/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module.exports = {
'parser': '@typescript-eslint/parser',
'extends': 'eslint:recommended',
'parserOptions': {
'ecmaVersion': 2018,
'sourceType': 'module'
},
'plugins': ['@typescript-eslint'],
'env': {
'browser': true,
'node': true,
'mocha': true
},
'globals': {},
'rules': {
indent: ['error', 4, {
SwitchCase: 1
}],
'no-empty': ['error', { 'allowEmptyCatch': true }],
quotes: ['error', 'single', {
avoidEscape: true
}],
/**
* The codebase uses some while(true) statements.
* Refactor to remove this rule.
*/
'no-constant-condition': 0,
/**
* Less combines assignments with conditionals sometimes
*/
'no-cond-assign': 0,
/**
* @todo - remove when some kind of code style (XO?) is added
*/
'no-multiple-empty-lines': 'error'
},
'overrides': [
{
files: ['*.ts'],
extends: ['plugin:@typescript-eslint/recommended'],
rules: {
/**
* Suppress until Less has better-defined types
* @see https://github.com/less/less.js/discussions/3786
*/
'@typescript-eslint/no-explicit-any': 0
}
},
{
files: ['test/**/*.{js,ts}', 'benchmark/index.js'],
/**
* @todo - fix later
*/
rules: {
'no-undef': 0,
'no-useless-escape': 0,
'no-unused-vars': 0,
'no-redeclare': 0,
'@typescript-eslint/no-unused-vars': 0
}
},
]
}
71 changes: 0 additions & 71 deletions packages/less/.eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/less/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ module.exports = function(grunt) {
"!test/less/errors/plugin/plugin-error.js"
],
options: {
configFile: ".eslintrc.json",
configFile: ".eslintrc.js",
fix: true
}
},
Expand Down
22 changes: 11 additions & 11 deletions packages/less/benchmark/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var path = require('path'),
fs = require('fs'),
now = require("performance-now");
now = require('performance-now');

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

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

var renderBenchmark = []
, parserBenchmark = []
, evalBenchmark = [];
, parserBenchmark = []
, evalBenchmark = [];

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

console.log("Min. Time: " + Math.round(mintime) + " ms");
console.log("Max. Time: " + Math.round(maxtime) + " ms");
console.log("Total Average Time: " + Math.round(avgtime) + " ms (" +
console.log('Min. Time: ' + Math.round(mintime) + ' ms');
console.log('Max. Time: ' + Math.round(maxtime) + ' ms');
console.log('Total Average Time: ' + Math.round(avgtime) + ' ms (' +
parseInt(1000 / avgtime *
data.length / 1024) + " KB\/s)");
console.log("+/- " + Math.round(variationperc) + "%");
console.log("");
data.length / 1024) + ' KB\/s)');
console.log('+/- ' + Math.round(variationperc) + '%');
console.log('');
}

analyze('Parsing', parserBenchmark);
Expand Down
2 changes: 1 addition & 1 deletion packages/less/build/rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function buildBrowser() {
include: [/^.+\.min\.js$/],
output: {
comments: function(node, comment) {
if (comment.type == "comment2") {
if (comment.type == 'comment2') {
// preserve banner
return /@license/i.test(comment.value);
}
Expand Down
6 changes: 4 additions & 2 deletions packages/less/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
"scripts": {
"test": "grunt test",
"grunt": "grunt",
"lint": "eslint '**/*.{ts,js}'",
"lint:fix": "eslint '**/*.{ts,js}' --fix",
"build": "npm-run-all clean compile",
"clean": "shx rm -rf ./lib tsconfig.tsbuildinfo",
"compile": "tsc -p tsconfig.json",
"compile": "tsc -p tsconfig.build.json",
"copy:root": "shx cp -rf ./dist ../../",
"dev": "tsc -p tsconfig.json -w",
"dev": "tsc -p tsconfig.build.json -w",
"prepublishOnly": "grunt dist"
},
"optionalDependencies": {
Expand Down
4 changes: 1 addition & 3 deletions packages/less/src/less-browser/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* used in the browser distributed version of less
* to kick-start less using the browser api
*/
/* global window, document */

import defaultOptions from '../less/default-options';
import addDefaultOptions from './add-default-options';
import root from './index';
Expand All @@ -13,7 +11,7 @@ const options = defaultOptions();

if (window.less) {
for (const key in window.less) {
if (window.less.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(window.less, key)) {
options[key] = window.less[key];
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/less/src/less-browser/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default (window, options, logger) => {
let vars = cache && cache.getItem(`${path}:vars`);

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

if (timestamp && webInfo.lastModified &&
(new Date(webInfo.lastModified).valueOf() ===
Expand Down
4 changes: 2 additions & 2 deletions packages/less/src/less-browser/error-reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default (window, less, options) => {
let content;
const errors = [];
const filename = e.filename || rootHref;
const filenameNoPath = filename.match(/([^\/]+(\?.*)?)$/)[1];
const filenameNoPath = filename.match(/([^/]+(\?.*)?)$/)[1];

elem.id = id;
elem.className = 'less-error-message';
Expand Down Expand Up @@ -113,7 +113,7 @@ export default (window, less, options) => {
}
}

function removeErrorConsole(path) {
function removeErrorConsole() {
// no action
}

Expand Down
4 changes: 1 addition & 3 deletions packages/less/src/less-browser/file-manager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* global window, XMLHttpRequest */

import AbstractFileManager from '../less/environment/abstract-file-manager.js';

let options;
Expand Down Expand Up @@ -66,7 +64,7 @@ FileManager.prototype = Object.assign(new AbstractFileManager(), {
fileCache = {};
},

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

Expand Down
10 changes: 7 additions & 3 deletions packages/less/src/less-browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default (window, options) => {
function clone(obj) {
const cloned = {};
for (const prop in obj) {
if (obj.hasOwnProperty(prop)) {
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
cloned[prop] = obj[prop];
}
}
Expand Down Expand Up @@ -159,6 +159,10 @@ export default (window, options) => {
less.watchTimer = setInterval(() => {
if (less.watchMode) {
fileManager.clearFileCache();
/**
* @todo remove when this is typed with JSDoc
*/
// eslint-disable-next-line no-unused-vars
loadStyleSheets((e, css, _, sheet, webInfo) => {
if (e) {
errors.add(e, e.href || sheet.href);
Expand All @@ -174,7 +178,7 @@ export default (window, options) => {
//
// Watch mode
//
less.watch = function () {
less.watch = function () {
if (!less.watchMode ) {
less.env = 'development';
initRunningMode();
Expand Down Expand Up @@ -205,7 +209,7 @@ export default (window, options) => {
// Asynchronously get all <link> tags with the 'rel' attribute set to
// "stylesheet/less", returning a Promise.
//
less.registerStylesheets = () => new Promise((resolve, reject) => {
less.registerStylesheets = () => new Promise((resolve) => {
less.registerStylesheetsImmediately();
resolve();
});
Expand Down
6 changes: 3 additions & 3 deletions packages/less/src/less-browser/plugin-loader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// TODO: Add tests for browser @plugin
/* global window */

/**
* @todo Add tests for browser `@plugin`
*/
import AbstractPluginLoader from '../less/environment/abstract-plugin-loader.js';

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/less/src/less-browser/utils.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@

export function extractId(href) {
return href.replace(/^[a-z-]+:\/+?[^\/]+/, '') // Remove protocol & domain
.replace(/[\?\&]livereload=\w+/, '') // Remove LiveReload cachebuster
return href.replace(/^[a-z-]+:\/+?[^/]+/, '') // Remove protocol & domain
.replace(/[?&]livereload=\w+/, '') // Remove LiveReload cachebuster
.replace(/^\//, '') // Remove root /
.replace(/\.[a-zA-Z]+$/, '') // Remove simple extension
.replace(/[^\.\w-]+/g, '-') // Replace illegal characters
.replace(/[^.\w-]+/g, '-') // Replace illegal characters
.replace(/\./g, ':'); // Replace dots with colons(for valid id)
}

export function addDataAttr(options, tag) {
if (!tag) {return;} // in case of tag is null or undefined
for (const opt in tag.dataset) {
if (tag.dataset.hasOwnProperty(opt)) {
if (Object.prototype.hasOwnProperty.call(tag.dataset, opt)) {
if (opt === 'env' || opt === 'dumpLineNumbers' || opt === 'rootpath' || opt === 'errorReporting') {
options[opt] = tag.dataset[opt];
} else {
Expand Down
37 changes: 18 additions & 19 deletions packages/less/src/less-node/file-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ FileManager.prototype = Object.assign(new AbstractFileManager(), {

function getFileData(fulfill, reject) {
(function tryPathIndex(i) {
function tryWithExtension() {
const extFilename = options.ext ? self.tryAppendExtension(fullFilename, options.ext) : fullFilename;

if (extFilename !== fullFilename && !explicit && paths[i] === '.') {
try {
fullFilename = require.resolve(extFilename);
isNodeModule = true;
}
catch (e) {
filenamesTried.push(npmPrefix + extFilename);
fullFilename = extFilename;
}
}
else {
fullFilename = extFilename;
}
}
if (i < paths.length) {
(function tryPrefix(j) {
if (j < prefixes.length) {
Expand All @@ -83,25 +100,7 @@ FileManager.prototype = Object.assign(new AbstractFileManager(), {
}
else {
tryWithExtension();
}

function tryWithExtension() {
const extFilename = options.ext ? self.tryAppendExtension(fullFilename, options.ext) : fullFilename;

if (extFilename !== fullFilename && !explicit && paths[i] === '.') {
try {
fullFilename = require.resolve(extFilename);
isNodeModule = true;
}
catch (e) {
filenamesTried.push(npmPrefix + extFilename);
fullFilename = extFilename;
}
}
else {
fullFilename = extFilename;
}
}
}

const readFileArgs = [fullFilename];
if (!options.rawBuffer) {
Expand Down
Loading