Skip to content

code quality #896

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

Merged
merged 3 commits into from
Mar 21, 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
5 changes: 1 addition & 4 deletions .github/bin/format-package-json.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,9 @@ const formatted = {};
formatted.exports['.'] = {
types: packageJSONInfo.exports['.'].types,
...formatted.exports['.'],
}
};
}
delete packageJSONInfo.exports;
} else if (packageJSONInfo.exports) {
formatted.exports = packageJSONInfo.exports;
delete packageJSONInfo.exports;
}

formatted.files = packageJSONInfo.files;
Expand Down
1 change: 0 additions & 1 deletion .github/bin/release-plan/npm-version.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { spawn } from 'child_process';
import { npmInstall } from './npm-install.mjs';
import fs from 'fs/promises';
import path from 'path';

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ jobs:
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
queries: security-and-quality
queries: security-extended

- name: setup node
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
cache: 'npm'

- run: npm ci --ignore-scripts
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"use strict";var e=require("@csstools/css-parser-algorithms"),n=require("@csstools/css-calc"),o=require("@csstools/css-tokenizer");const t=/(repeating-)?(linear|radial|conic)-gradient\(/i,a=/^(repeating-)?(linear|radial|conic)-gradient$/i,i=/^(abs|acos|asin|atan|atan2|calc|clamp|cos|exp|hypot|log|max|min|mod|pow|rem|round|sign|sin|sqrt|tan)$/i,creator=n=>{const s=Object.assign({preserve:!1},n);return{postcssPlugin:"postcss-gradient-stop-increments",Declaration(n){if(!t.test(n.value))return;if(!o.tokenize({css:n.value}).find((e=>e[0]===o.TokenType.Delim&&"+"===e[4].value)))return;const r=replaceComponentValues(e.parseCommaSeparatedListOfComponentValues(o.tokenize({css:n.value})),(n=>{if(!e.isFunctionNode(n))return;const t=n.getName();if(!a.test(t))return;let s=null;for(let t=0;t<n.value.length;t++){const a=n.value[t];if(e.isTokenNode(a)&&a.value[0]===o.TokenType.Delim&&"+"===a.value[4].value){const i=a,r=t;for(;e.isCommentNode(n.value[t+1]);)t++;if(t++,isZeroOrNegative(n.value[t])){const a=new e.TokenNode([o.TokenType.Number,"0",-1,-1,{value:0,type:o.NumberType.Integer}]);n.value.splice(r,t-r+1,a),t=n.value.indexOf(a);continue}const c=incrementLengthNode(s,i,n.value[t]);n.value.splice(r,t-r+1,c),s=c,t=n.value.indexOf(c)}else(isNumericLargerThanZero(a)||e.isFunctionNode(a)&&i.test(a.getName()))&&(s=maxOfLastAndCurrentLengthNode(s,a))}})).map((e=>e.map((e=>o.stringify(...e.tokens()))).join(""))).join(",");r!==n.value&&(n.cloneBefore({value:r}),null!=s&&s.preserve||n.remove())}}};function isNumericLargerThanZero(n){return!(!e.isTokenNode(n)||n.value[0]!==o.TokenType.Percentage&&n.value[0]!==o.TokenType.Dimension&&n.value[0]!==o.TokenType.Number||!(n.value[4].value>0))}function isZeroOrNegative(n){return!(!e.isTokenNode(n)||n.value[0]!==o.TokenType.Percentage&&n.value[0]!==o.TokenType.Dimension&&n.value[0]!==o.TokenType.Number||!(n.value[4].value<=0))}function incrementLengthNode(t,a,i){if(!t)return i;const s=new e.FunctionNode([o.TokenType.Function,"calc(",-1,-1,{value:"calc"}],[o.TokenType.CloseParen,")",-1,-1,void 0],[t,new e.WhitespaceNode([[o.TokenType.Whitespace," ",-1,-1,void 0]]),a,new e.WhitespaceNode([[o.TokenType.Whitespace," ",-1,-1,void 0]]),i]),[[r]]=n.calcFromComponentValues([[s]]);return r}function maxOfLastAndCurrentLengthNode(t,a){if(!t)return a;const i=new e.FunctionNode([o.TokenType.Function,"max(",-1,-1,{value:"max"}],[o.TokenType.CloseParen,")",-1,-1,void 0],[t,new e.TokenNode([o.TokenType.Comma,",",-1,-1,void 0]),new e.WhitespaceNode([[o.TokenType.Whitespace," ",-1,-1,void 0]]),a]),[[s]]=n.calcFromComponentValues([[i]]);return s}function replaceComponentValues(n,o){for(let t=0;t<n.length;t++){const a=n[t];for(let n=0;n<a.length;n++){const t=a[n];{const e=o(t);if(e){a.splice(n,1,e);continue}}(e.isSimpleBlockNode(t)||e.isFunctionNode(t))&&t.walk(((e,n)=>{if("number"!=typeof n)return;const t=e.node,a=o(t);a&&e.parent.value.splice(n,1,a)}))}}return n}creator.postcss=!0,module.exports=creator;
"use strict";var e=require("@csstools/css-parser-algorithms"),n=require("@csstools/css-calc"),o=require("@csstools/css-tokenizer");const t=/(repeating-)?(linear|radial|conic)-gradient\(/i,a=/^(repeating-)?(linear|radial|conic)-gradient$/i,i=/^(abs|acos|asin|atan|atan2|calc|clamp|cos|exp|hypot|log|max|min|mod|pow|rem|round|sign|sin|sqrt|tan)$/i,creator=n=>{const s=Object.assign({preserve:!1},n);return{postcssPlugin:"postcss-gradient-stop-increments",Declaration(n){if(!t.test(n.value))return;if(!o.tokenize({css:n.value}).find((e=>e[0]===o.TokenType.Delim&&"+"===e[4].value)))return;const r=replaceComponentValues(e.parseCommaSeparatedListOfComponentValues(o.tokenize({css:n.value})),(n=>{if(!e.isFunctionNode(n))return;const t=n.getName();if(!a.test(t))return;let s=null;for(let t=0;t<n.value.length;t++){const a=n.value[t];if(e.isTokenNode(a)&&a.value[0]===o.TokenType.Delim&&"+"===a.value[4].value){const i=a,r=t;for(;e.isCommentNode(n.value[t+1]);)t++;if(t++,isZeroOrNegative(n.value[t])){const a=new e.TokenNode([o.TokenType.Number,"0",-1,-1,{value:0,type:o.NumberType.Integer}]);n.value.splice(r,t-r+1,a),t=n.value.indexOf(a);continue}const l=incrementLengthNode(s,i,n.value[t]);n.value.splice(r,t-r+1,l),s=l,t=n.value.indexOf(l)}else(isNumericLargerThanZero(a)||e.isFunctionNode(a)&&i.test(a.getName()))&&(s=maxOfLastAndCurrentLengthNode(s,a))}})).map((e=>e.map((e=>o.stringify(...e.tokens()))).join(""))).join(",");r!==n.value&&(n.cloneBefore({value:r}),null!=s&&s.preserve||n.remove())}}};function isNumericLargerThanZero(n){return!(!e.isTokenNode(n)||n.value[0]!==o.TokenType.Percentage&&n.value[0]!==o.TokenType.Dimension&&n.value[0]!==o.TokenType.Number||!(n.value[4].value>0))}function isZeroOrNegative(n){return!(!e.isTokenNode(n)||n.value[0]!==o.TokenType.Percentage&&n.value[0]!==o.TokenType.Dimension&&n.value[0]!==o.TokenType.Number||!(n.value[4].value<=0))}function incrementLengthNode(t,a,i){if(!t)return i;const s=new e.FunctionNode([o.TokenType.Function,"calc(",-1,-1,{value:"calc"}],[o.TokenType.CloseParen,")",-1,-1,void 0],[t,new e.WhitespaceNode([[o.TokenType.Whitespace," ",-1,-1,void 0]]),a,new e.WhitespaceNode([[o.TokenType.Whitespace," ",-1,-1,void 0]]),i]),[[r]]=n.calcFromComponentValues([[s]]);return r}function maxOfLastAndCurrentLengthNode(t,a){if(!t)return a;const i=new e.FunctionNode([o.TokenType.Function,"max(",-1,-1,{value:"max"}],[o.TokenType.CloseParen,")",-1,-1,void 0],[t,new e.TokenNode([o.TokenType.Comma,",",-1,-1,void 0]),new e.WhitespaceNode([[o.TokenType.Whitespace," ",-1,-1,void 0]]),a]),[[s]]=n.calcFromComponentValues([[i]]);return s}function replaceComponentValues(n,o){for(let t=0;t<n.length;t++){const a=n[t];for(let n=0;n<a.length;n++){const t=a[n];o(t),(e.isSimpleBlockNode(t)||e.isFunctionNode(t))&&t.walk(((e,n)=>{"number"==typeof n&&o(e.node)}))}}return n}creator.postcss=!0,module.exports=creator;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import{parseCommaSeparatedListOfComponentValues as e,isSimpleBlockNode as n,isFunctionNode as t,isTokenNode as a,isCommentNode as r,TokenNode as o,FunctionNode as s,WhitespaceNode as i}from"@csstools/css-parser-algorithms";import{calcFromComponentValues as l}from"@csstools/css-calc";import{tokenize as u,TokenType as c,stringify as v,NumberType as m}from"@csstools/css-tokenizer";const p=/(repeating-)?(linear|radial|conic)-gradient\(/i,f=/^(repeating-)?(linear|radial|conic)-gradient$/i,g=/^(abs|acos|asin|atan|atan2|calc|clamp|cos|exp|hypot|log|max|min|mod|pow|rem|round|sign|sin|sqrt|tan)$/i,creator=n=>{const s=Object.assign({preserve:!1},n);return{postcssPlugin:"postcss-gradient-stop-increments",Declaration(n){if(!p.test(n.value))return;if(!u({css:n.value}).find((e=>e[0]===c.Delim&&"+"===e[4].value)))return;const i=replaceComponentValues(e(u({css:n.value})),(e=>{if(!t(e))return;const n=e.getName();if(!f.test(n))return;let s=null;for(let n=0;n<e.value.length;n++){const i=e.value[n];if(a(i)&&i.value[0]===c.Delim&&"+"===i.value[4].value){const t=i,a=n;for(;r(e.value[n+1]);)n++;if(n++,isZeroOrNegative(e.value[n])){const t=new o([c.Number,"0",-1,-1,{value:0,type:m.Integer}]);e.value.splice(a,n-a+1,t),n=e.value.indexOf(t);continue}const l=incrementLengthNode(s,t,e.value[n]);e.value.splice(a,n-a+1,l),s=l,n=e.value.indexOf(l)}else(isNumericLargerThanZero(i)||t(i)&&g.test(i.getName()))&&(s=maxOfLastAndCurrentLengthNode(s,i))}})).map((e=>e.map((e=>v(...e.tokens()))).join(""))).join(",");i!==n.value&&(n.cloneBefore({value:i}),null!=s&&s.preserve||n.remove())}}};function isNumericLargerThanZero(e){return!(!a(e)||e.value[0]!==c.Percentage&&e.value[0]!==c.Dimension&&e.value[0]!==c.Number||!(e.value[4].value>0))}function isZeroOrNegative(e){return!(!a(e)||e.value[0]!==c.Percentage&&e.value[0]!==c.Dimension&&e.value[0]!==c.Number||!(e.value[4].value<=0))}function incrementLengthNode(e,n,t){if(!e)return t;const a=new s([c.Function,"calc(",-1,-1,{value:"calc"}],[c.CloseParen,")",-1,-1,void 0],[e,new i([[c.Whitespace," ",-1,-1,void 0]]),n,new i([[c.Whitespace," ",-1,-1,void 0]]),t]),[[r]]=l([[a]]);return r}function maxOfLastAndCurrentLengthNode(e,n){if(!e)return n;const t=new s([c.Function,"max(",-1,-1,{value:"max"}],[c.CloseParen,")",-1,-1,void 0],[e,new o([c.Comma,",",-1,-1,void 0]),new i([[c.Whitespace," ",-1,-1,void 0]]),n]),[[a]]=l([[t]]);return a}function replaceComponentValues(e,a){for(let r=0;r<e.length;r++){const o=e[r];for(let e=0;e<o.length;e++){const r=o[e];{const n=a(r);if(n){o.splice(e,1,n);continue}}(n(r)||t(r))&&r.walk(((e,n)=>{if("number"!=typeof n)return;const t=e.node,r=a(t);r&&e.parent.value.splice(n,1,r)}))}}return e}creator.postcss=!0;export{creator as default};
import{parseCommaSeparatedListOfComponentValues as e,isSimpleBlockNode as n,isFunctionNode as t,isTokenNode as a,isCommentNode as r,TokenNode as o,FunctionNode as s,WhitespaceNode as i}from"@csstools/css-parser-algorithms";import{calcFromComponentValues as l}from"@csstools/css-calc";import{tokenize as u,TokenType as c,stringify as v,NumberType as m}from"@csstools/css-tokenizer";const p=/(repeating-)?(linear|radial|conic)-gradient\(/i,f=/^(repeating-)?(linear|radial|conic)-gradient$/i,g=/^(abs|acos|asin|atan|atan2|calc|clamp|cos|exp|hypot|log|max|min|mod|pow|rem|round|sign|sin|sqrt|tan)$/i,creator=n=>{const s=Object.assign({preserve:!1},n);return{postcssPlugin:"postcss-gradient-stop-increments",Declaration(n){if(!p.test(n.value))return;if(!u({css:n.value}).find((e=>e[0]===c.Delim&&"+"===e[4].value)))return;const i=replaceComponentValues(e(u({css:n.value})),(e=>{if(!t(e))return;const n=e.getName();if(!f.test(n))return;let s=null;for(let n=0;n<e.value.length;n++){const i=e.value[n];if(a(i)&&i.value[0]===c.Delim&&"+"===i.value[4].value){const t=i,a=n;for(;r(e.value[n+1]);)n++;if(n++,isZeroOrNegative(e.value[n])){const t=new o([c.Number,"0",-1,-1,{value:0,type:m.Integer}]);e.value.splice(a,n-a+1,t),n=e.value.indexOf(t);continue}const l=incrementLengthNode(s,t,e.value[n]);e.value.splice(a,n-a+1,l),s=l,n=e.value.indexOf(l)}else(isNumericLargerThanZero(i)||t(i)&&g.test(i.getName()))&&(s=maxOfLastAndCurrentLengthNode(s,i))}})).map((e=>e.map((e=>v(...e.tokens()))).join(""))).join(",");i!==n.value&&(n.cloneBefore({value:i}),null!=s&&s.preserve||n.remove())}}};function isNumericLargerThanZero(e){return!(!a(e)||e.value[0]!==c.Percentage&&e.value[0]!==c.Dimension&&e.value[0]!==c.Number||!(e.value[4].value>0))}function isZeroOrNegative(e){return!(!a(e)||e.value[0]!==c.Percentage&&e.value[0]!==c.Dimension&&e.value[0]!==c.Number||!(e.value[4].value<=0))}function incrementLengthNode(e,n,t){if(!e)return t;const a=new s([c.Function,"calc(",-1,-1,{value:"calc"}],[c.CloseParen,")",-1,-1,void 0],[e,new i([[c.Whitespace," ",-1,-1,void 0]]),n,new i([[c.Whitespace," ",-1,-1,void 0]]),t]),[[r]]=l([[a]]);return r}function maxOfLastAndCurrentLengthNode(e,n){if(!e)return n;const t=new s([c.Function,"max(",-1,-1,{value:"max"}],[c.CloseParen,")",-1,-1,void 0],[e,new o([c.Comma,",",-1,-1,void 0]),new i([[c.Whitespace," ",-1,-1,void 0]]),n]),[[a]]=l([[t]]);return a}function replaceComponentValues(e,a){for(let r=0;r<e.length;r++){const o=e[r];for(let e=0;e<o.length;e++){const r=o[e];a(r),(n(r)||t(r))&&r.walk(((e,n)=>{"number"==typeof n&&a(e.node)}))}}return e}creator.postcss=!0;export{creator as default};
2 changes: 1 addition & 1 deletion experimental/postcss-gradient-stop-increments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"repository": {
"type": "git",
"url": "https://github.com/csstools/postcss-plugins.git",
"directory": "plugins/postcss-gradient-stop-increments"
"directory": "experimental/postcss-gradient-stop-increments"
},
"bugs": "https://github.com/csstools/postcss-plugins/issues",
"keywords": [
Expand Down
17 changes: 3 additions & 14 deletions experimental/postcss-gradient-stop-increments/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,34 +204,23 @@ function maxOfLastAndCurrentLengthNode(lastLengthNode: ComponentValue | null, ne
// TODO : this should be in css-parser-algorithms, will be present in an upcoming release
function replaceComponentValues(
componentValuesList: Array<Array<ComponentValue>>,
replaceWith: (componentValue: ComponentValue) => ComponentValue | void,
visitor: (componentValue: ComponentValue) => ComponentValue | void,
) {
for (let i = 0; i < componentValuesList.length; i++) {
const componentValues = componentValuesList[i];

for (let j = 0; j < componentValues.length; j++) {
const componentValue = componentValues[j];

{
const replacement = replaceWith(componentValue);
if (replacement) {
componentValues.splice(j, 1, replacement);
continue;
}
}
visitor(componentValue);

if (isSimpleBlockNode(componentValue) || isFunctionNode(componentValue)) {
componentValue.walk((entry, index) => {
if (typeof index !== 'number') {
return;
}

const node = entry.node;
const replacement = replaceWith(node);
if (replacement) {
entry.parent.value.splice(index, 1, replacement);
return;
}
visitor(entry.node);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/css-calc/dist/index.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/css-calc/dist/index.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/css-calc/src/util/patch-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { patchCanonicalUnit } from './canonical-unit';
import { conversionOptions } from '../options';

export function patchCalcResult(x: TokenNode | FunctionNode | -1, options?: conversionOptions): TokenNode | FunctionNode | -1 {
let y = x;
let y: TokenNode | FunctionNode | -1;
y = patchNaN(x);
y = patchInfinity(y);

Expand Down
Loading