From 595903b4fe5aa793a8123057a2fa15d567660e5e Mon Sep 17 00:00:00 2001 From: lumburr Date: Fri, 1 Apr 2022 21:58:52 +0800 Subject: [PATCH 1/3] fix: ESlint warning --- packages/less/.eslintrc.json | 3 +-- packages/less/package.json | 4 +--- packages/less/src/less-browser/utils.js | 2 +- packages/less/src/less/environment/environment.js | 3 ++- packages/less/src/less/functions/default.js | 3 ++- packages/less/src/less/functions/math-helper.js | 3 ++- packages/less/src/less/parser/parser.js | 2 +- packages/less/src/less/tree/node.js | 8 +++++--- packages/less/src/less/tree/quoted.js | 3 ++- packages/less/src/less/tree/ruleset.js | 2 +- packages/less/src/less/tree/selector.js | 3 ++- packages/less/src/less/utils.js | 4 ++++ 12 files changed, 24 insertions(+), 16 deletions(-) diff --git a/packages/less/.eslintrc.json b/packages/less/.eslintrc.json index 9713bafa8..da3174afb 100644 --- a/packages/less/.eslintrc.json +++ b/packages/less/.eslintrc.json @@ -1,10 +1,9 @@ { - "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": 2018, "sourceType": "module" }, - "plugins": ["@typescript-eslint"], + "plugins": [], "env": { "browser": true, "node": true diff --git a/packages/less/package.json b/packages/less/package.json index 5976af2f0..55f85f30a 100644 --- a/packages/less/package.json +++ b/packages/less/package.json @@ -59,14 +59,12 @@ "@rollup/plugin-commonjs": "^17.0.0", "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^11.0.0", - "@typescript-eslint/eslint-plugin": "^4.28.0", - "@typescript-eslint/parser": "^4.28.0", "benny": "^3.6.12", "bootstrap-less-port": "0.3.0", "chai": "^4.2.0", "cross-env": "^7.0.3", "diff": "^3.2.0", - "eslint": "^7.29.0", + "eslint": "^8.10.0", "fs-extra": "^8.1.0", "git-rev": "^0.2.1", "globby": "^10.0.1", diff --git a/packages/less/src/less-browser/utils.js b/packages/less/src/less-browser/utils.js index 42a1b442e..039f1d595 100644 --- a/packages/less/src/less-browser/utils.js +++ b/packages/less/src/less-browser/utils.js @@ -9,7 +9,7 @@ export function extractId(href) { } export function addDataAttr(options, tag) { - if(!tag) return; // in case of tag is null or undefined + if (!tag) {return;} // in case of tag is null or undefined for (const opt in tag.dataset) { if (tag.dataset.hasOwnProperty(opt)) { if (opt === 'env' || opt === 'dumpLineNumbers' || opt === 'rootpath' || opt === 'errorReporting') { diff --git a/packages/less/src/less/environment/environment.js b/packages/less/src/less/environment/environment.js index 39de0d315..ce85ad6a8 100644 --- a/packages/less/src/less/environment/environment.js +++ b/packages/less/src/less/environment/environment.js @@ -4,6 +4,7 @@ */ import logger from '../logger'; +import * as utils from '../utils'; class Environment { constructor(externalEnvironment, fileManagers) { @@ -30,7 +31,7 @@ class Environment { if (!filename) { logger.warn('getFileManager called with no filename.. Please report this issue. continuing.'); } - if (currentDirectory == null) { + if (utils.isNullOrUndefined(currentDirectory)) { logger.warn('getFileManager called with null directory.. Please report this issue. continuing.'); } diff --git a/packages/less/src/less/functions/default.js b/packages/less/src/less/functions/default.js index fc7fd63aa..61c14b9ac 100644 --- a/packages/less/src/less/functions/default.js +++ b/packages/less/src/less/functions/default.js @@ -1,4 +1,5 @@ import Keyword from '../tree/keyword'; +import * as utils from '../utils'; const defaultFunc = { eval: function () { @@ -7,7 +8,7 @@ const defaultFunc = { if (e) { throw e; } - if (v != null) { + if (!utils.isNullOrUndefined(v)) { return v ? Keyword.True : Keyword.False; } }, diff --git a/packages/less/src/less/functions/math-helper.js b/packages/less/src/less/functions/math-helper.js index ed6deaa75..e2bebce87 100644 --- a/packages/less/src/less/functions/math-helper.js +++ b/packages/less/src/less/functions/math-helper.js @@ -1,10 +1,11 @@ import Dimension from '../tree/dimension'; +import * as utils from '../utils'; const MathHelper = (fn, unit, n) => { if (!(n instanceof Dimension)) { throw { type: 'Argument', message: 'argument must be a number' }; } - if (unit == null) { + if (utils.isNullOrUndefined(unit)) { unit = n.unit; } else { n = n.unify(); diff --git a/packages/less/src/less/parser/parser.js b/packages/less/src/less/parser/parser.js index c7a65cb07..ea3383623 100644 --- a/packages/less/src/less/parser/parser.js +++ b/packages/less/src/less/parser/parser.js @@ -581,7 +581,7 @@ const Parser = function Parser(context, imports, fileInfo) { expectChar(')'); - return new(tree.URL)((value.value != null || + return new(tree.URL)((!utils.isNullOrUndefined(value.value) || value instanceof tree.Variable || value instanceof tree.Property) ? value : new(tree.Anonymous)(value, index), index, fileInfo); diff --git a/packages/less/src/less/tree/node.js b/packages/less/src/less/tree/node.js index b40e30da9..b2c74aff8 100644 --- a/packages/less/src/less/tree/node.js +++ b/packages/less/src/less/tree/node.js @@ -1,3 +1,5 @@ +import * as utils from '../utils'; + /** * The reason why Node is a class and other nodes simply do not extend * from Node (since we're transpiling) is due to this issue: @@ -125,21 +127,21 @@ class Node { // Returns true if this node represents root of ast imported by reference blocksVisibility() { - if (this.visibilityBlocks == null) { + if (utils.isNullOrUndefined(this.visibilityBlocks)) { this.visibilityBlocks = 0; } return this.visibilityBlocks !== 0; } addVisibilityBlock() { - if (this.visibilityBlocks == null) { + if (utils.isNullOrUndefined(this.visibilityBlocks)) { this.visibilityBlocks = 0; } this.visibilityBlocks = this.visibilityBlocks + 1; } removeVisibilityBlock() { - if (this.visibilityBlocks == null) { + if (utils.isNullOrUndefined(this.visibilityBlocks)) { this.visibilityBlocks = 0; } this.visibilityBlocks = this.visibilityBlocks - 1; diff --git a/packages/less/src/less/tree/quoted.js b/packages/less/src/less/tree/quoted.js index d73c40ca6..20ea852a1 100644 --- a/packages/less/src/less/tree/quoted.js +++ b/packages/less/src/less/tree/quoted.js @@ -1,10 +1,11 @@ import Node from './node'; import Variable from './variable'; import Property from './property'; +import * as utils from '../utils'; const Quoted = function(str, content, escaped, index, currentFileInfo) { - this.escaped = (escaped == null) ? true : escaped; + this.escaped = utils.isNullOrUndefined(escaped) ? true : escaped; this.value = content || ''; this.quote = str.charAt(0); this._index = index; diff --git a/packages/less/src/less/tree/ruleset.js b/packages/less/src/less/tree/ruleset.js index 22f68b75c..fbbe51be3 100644 --- a/packages/less/src/less/tree/ruleset.js +++ b/packages/less/src/less/tree/ruleset.js @@ -734,7 +734,7 @@ Ruleset.prototype = Object.assign(new Node(), { // non parent reference elements just get added if (el.value !== '&') { const nestedSelector = findNestedSelector(el); - if (nestedSelector != null) { + if (!utils.isNullOrUndefined(nestedSelector)) { // merge the current list of non parent selector elements // on to the current list of selectors to add mergeElementsOnToSelectors(currentElements, newSelectors); diff --git a/packages/less/src/less/tree/selector.js b/packages/less/src/less/tree/selector.js index a198a7740..d098cc2bc 100644 --- a/packages/less/src/less/tree/selector.js +++ b/packages/less/src/less/tree/selector.js @@ -1,6 +1,7 @@ import Node from './node'; import Element from './element'; import LessError from '../less-error'; +import * as utils from '../utils'; const Selector = function(elements, extendList, condition, index, currentFileInfo, visibilityInfo) { this.extendList = extendList; @@ -33,7 +34,7 @@ Selector.prototype = Object.assign(new Node(), { elements = this.getElements(elements); const newSelector = new Selector(elements, extendList || this.extendList, null, this.getIndex(), this.fileInfo(), this.visibilityInfo()); - newSelector.evaldCondition = (evaldCondition != null) ? evaldCondition : this.evaldCondition; + newSelector.evaldCondition = (!utils.isNullOrUndefined(evaldCondition)) ? evaldCondition : this.evaldCondition; newSelector.mediaEmpty = this.mediaEmpty; return newSelector; }, diff --git a/packages/less/src/less/utils.js b/packages/less/src/less/utils.js index c0921b90d..b723ab2ac 100644 --- a/packages/less/src/less/utils.js +++ b/packages/less/src/less/utils.js @@ -119,4 +119,8 @@ export function flattenArray(arr, result = []) { } } return result; +} + +export function isNullOrUndefined(val) { + return val === null || val === undefined } \ No newline at end of file From db88cc3877c84b6441c9642ba199481e21901cf7 Mon Sep 17 00:00:00 2001 From: lumburr Date: Sat, 2 Apr 2022 10:46:51 +0800 Subject: [PATCH 2/3] fallback ts configuration --- packages/less/.eslintrc.json | 3 ++- packages/less/package.json | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/less/.eslintrc.json b/packages/less/.eslintrc.json index da3174afb..9713bafa8 100644 --- a/packages/less/.eslintrc.json +++ b/packages/less/.eslintrc.json @@ -1,9 +1,10 @@ { + "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": 2018, "sourceType": "module" }, - "plugins": [], + "plugins": ["@typescript-eslint"], "env": { "browser": true, "node": true diff --git a/packages/less/package.json b/packages/less/package.json index 55f85f30a..1a09a13a9 100644 --- a/packages/less/package.json +++ b/packages/less/package.json @@ -59,6 +59,8 @@ "@rollup/plugin-commonjs": "^17.0.0", "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^11.0.0", + "@typescript-eslint/eslint-plugin": "^4.28.0", + "@typescript-eslint/parser": "^4.28.0", "benny": "^3.6.12", "bootstrap-less-port": "0.3.0", "chai": "^4.2.0", From 8cf010ee3d0b3e4128b135ed3d561dfbbd191f80 Mon Sep 17 00:00:00 2001 From: lumburr Date: Tue, 26 Apr 2022 17:13:56 +0800 Subject: [PATCH 3/3] fix: analysis value to fix ESlint warning && fallback eslint version --- packages/less/package.json | 2 +- packages/less/src/less/environment/environment.js | 3 +-- packages/less/src/less/functions/math-helper.js | 3 +-- packages/less/src/less/parser/parser.js | 2 +- packages/less/src/less/tree/node.js | 6 +++--- packages/less/src/less/tree/quoted.js | 2 +- packages/less/src/less/tree/ruleset.js | 2 +- 7 files changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/less/package.json b/packages/less/package.json index 1a09a13a9..5976af2f0 100644 --- a/packages/less/package.json +++ b/packages/less/package.json @@ -66,7 +66,7 @@ "chai": "^4.2.0", "cross-env": "^7.0.3", "diff": "^3.2.0", - "eslint": "^8.10.0", + "eslint": "^7.29.0", "fs-extra": "^8.1.0", "git-rev": "^0.2.1", "globby": "^10.0.1", diff --git a/packages/less/src/less/environment/environment.js b/packages/less/src/less/environment/environment.js index ce85ad6a8..f7d65c6a1 100644 --- a/packages/less/src/less/environment/environment.js +++ b/packages/less/src/less/environment/environment.js @@ -4,7 +4,6 @@ */ import logger from '../logger'; -import * as utils from '../utils'; class Environment { constructor(externalEnvironment, fileManagers) { @@ -31,7 +30,7 @@ class Environment { if (!filename) { logger.warn('getFileManager called with no filename.. Please report this issue. continuing.'); } - if (utils.isNullOrUndefined(currentDirectory)) { + if (currentDirectory === undefined) { logger.warn('getFileManager called with null directory.. Please report this issue. continuing.'); } diff --git a/packages/less/src/less/functions/math-helper.js b/packages/less/src/less/functions/math-helper.js index e2bebce87..b557875c5 100644 --- a/packages/less/src/less/functions/math-helper.js +++ b/packages/less/src/less/functions/math-helper.js @@ -1,11 +1,10 @@ import Dimension from '../tree/dimension'; -import * as utils from '../utils'; const MathHelper = (fn, unit, n) => { if (!(n instanceof Dimension)) { throw { type: 'Argument', message: 'argument must be a number' }; } - if (utils.isNullOrUndefined(unit)) { + if (unit === null) { unit = n.unit; } else { n = n.unify(); diff --git a/packages/less/src/less/parser/parser.js b/packages/less/src/less/parser/parser.js index ea3383623..2b2799c62 100644 --- a/packages/less/src/less/parser/parser.js +++ b/packages/less/src/less/parser/parser.js @@ -581,7 +581,7 @@ const Parser = function Parser(context, imports, fileInfo) { expectChar(')'); - return new(tree.URL)((!utils.isNullOrUndefined(value.value) || + return new(tree.URL)((value.value !== undefined || value instanceof tree.Variable || value instanceof tree.Property) ? value : new(tree.Anonymous)(value, index), index, fileInfo); diff --git a/packages/less/src/less/tree/node.js b/packages/less/src/less/tree/node.js index b2c74aff8..4aadc261c 100644 --- a/packages/less/src/less/tree/node.js +++ b/packages/less/src/less/tree/node.js @@ -127,21 +127,21 @@ class Node { // Returns true if this node represents root of ast imported by reference blocksVisibility() { - if (utils.isNullOrUndefined(this.visibilityBlocks)) { + if (this.visibilityBlocks === undefined) { this.visibilityBlocks = 0; } return this.visibilityBlocks !== 0; } addVisibilityBlock() { - if (utils.isNullOrUndefined(this.visibilityBlocks)) { + if (this.visibilityBlocks === undefined) { this.visibilityBlocks = 0; } this.visibilityBlocks = this.visibilityBlocks + 1; } removeVisibilityBlock() { - if (utils.isNullOrUndefined(this.visibilityBlocks)) { + if (this.visibilityBlocks === undefined) { this.visibilityBlocks = 0; } this.visibilityBlocks = this.visibilityBlocks - 1; diff --git a/packages/less/src/less/tree/quoted.js b/packages/less/src/less/tree/quoted.js index 20ea852a1..7c96c0ecd 100644 --- a/packages/less/src/less/tree/quoted.js +++ b/packages/less/src/less/tree/quoted.js @@ -5,7 +5,7 @@ import * as utils from '../utils'; const Quoted = function(str, content, escaped, index, currentFileInfo) { - this.escaped = utils.isNullOrUndefined(escaped) ? true : escaped; + this.escaped = (escaped === undefined) ? true : escaped; this.value = content || ''; this.quote = str.charAt(0); this._index = index; diff --git a/packages/less/src/less/tree/ruleset.js b/packages/less/src/less/tree/ruleset.js index fbbe51be3..dfd044932 100644 --- a/packages/less/src/less/tree/ruleset.js +++ b/packages/less/src/less/tree/ruleset.js @@ -734,7 +734,7 @@ Ruleset.prototype = Object.assign(new Node(), { // non parent reference elements just get added if (el.value !== '&') { const nestedSelector = findNestedSelector(el); - if (!utils.isNullOrUndefined(nestedSelector)) { + if (nestedSelector !== null) { // merge the current list of non parent selector elements // on to the current list of selectors to add mergeElementsOnToSelectors(currentElements, newSelectors);