added all files to project

This commit is contained in:
2022-03-10 10:36:59 +01:00
parent 09dd957b33
commit 46a936d7de
25351 changed files with 3883356 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
# length-zero-no-unit
Disallow units for zero lengths.
<!-- prettier-ignore -->
```css
a { top: 0px; }
/** ↑↑
* This zero and this type of length unit */
```
_Lengths_ refer to distance measurements. A length is a _dimension_, which is a _number_ immediately followed by a _unit identifier_. However, for zero lengths the unit identifier is optional. The length units are: `em`, `ex`, `ch`, `vw`, `vh`, `cm`, `mm`, `in`, `pt`, `pc`, `px`, `rem`, `vmin`, and `vmax`.
This rule ignores lengths within math functions (e.g. `calc`) in favor of the [`function-calc-no-invalid`](../function-calc-no-invalid/README.md) rule.
The [`fix` option](../../../docs/user-guide/usage/options.md#fix) can automatically fix all of the problems reported by this rule.
## Options
### `true`
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a { top: 0px }
```
<!-- prettier-ignore -->
```css
a { top: 0.000em }
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a { top: 0 } /* no unit */
```
<!-- prettier-ignore -->
```css
a { transition-delay: 0s; } /* dimension */
```
<!-- prettier-ignore -->
```css
a { top: 2in; }
```
<!-- prettier-ignore -->
```css
a { top: 1.001vh }
```
## Optional secondary options
### `ignore: ["custom-properties"]`
#### `"custom-properties"`
Ignore units for zero length in custom properties.
The following pattern is _not_ considered a violation:
<!-- prettier-ignore -->
```css
a { --x: 0px; }
```
+163
View File
@@ -0,0 +1,163 @@
// @ts-nocheck
'use strict';
const valueParser = require('postcss-value-parser');
const atRuleParamIndex = require('../../utils/atRuleParamIndex');
const declarationValueIndex = require('../../utils/declarationValueIndex');
const getAtRuleParams = require('../../utils/getAtRuleParams');
const getDeclarationValue = require('../../utils/getDeclarationValue');
const isCustomProperty = require('../../utils/isCustomProperty');
const isMathFunction = require('../../utils/isMathFunction');
const isStandardSyntaxAtRule = require('../../utils/isStandardSyntaxAtRule');
const keywordSets = require('../../reference/keywordSets');
const optionsMatches = require('../../utils/optionsMatches');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const setAtRuleParams = require('../../utils/setAtRuleParams');
const setDeclarationValue = require('../../utils/setDeclarationValue');
const validateOptions = require('../../utils/validateOptions');
const ruleName = 'length-zero-no-unit';
const messages = ruleMessages(ruleName, {
rejected: 'Unexpected unit',
});
function rule(primary, secondary, context) {
return (root, result) => {
const validOptions = validateOptions(
result,
ruleName,
{
actual: primary,
},
{
actual: secondary,
possible: {
ignore: ['custom-properties'],
},
optional: true,
},
);
if (!validOptions) return;
let needsFix;
function check(node, nodeIndex, valueNode) {
const { value, sourceIndex } = valueNode;
if (isMathFunction(valueNode)) return false;
if (!isWord(valueNode)) return;
const numberUnit = valueParser.unit(value);
if (numberUnit === false) return;
const { number, unit } = numberUnit;
if (unit === '') return;
if (!isLength(unit)) return;
if (isFraction(unit)) return;
if (!isZero(number)) return;
if (context.fix) {
valueNode.value = number;
needsFix = true;
return;
}
report({
index: nodeIndex + sourceIndex + number.length,
message: messages.rejected,
node,
result,
ruleName,
});
}
function checkAtRule(node) {
if (!isStandardSyntaxAtRule(node)) return;
needsFix = false;
const index = atRuleParamIndex(node);
const parsedValue = valueParser(getAtRuleParams(node));
parsedValue.walk((valueNode) => {
return check(node, index, valueNode);
});
if (needsFix) {
setAtRuleParams(node, parsedValue.toString());
}
}
function checkDecl(node) {
needsFix = false;
const { prop } = node;
if (isLineHeight(prop)) return;
if (optionsMatches(secondary, 'ignore', 'custom-properties') && isCustomProperty(prop))
return;
const index = declarationValueIndex(node);
const parsedValue = valueParser(getDeclarationValue(node));
parsedValue.walk((valueNode, valueNodeIndex, valueNodes) => {
if (isLineHeightValue(node, valueNodes, valueNodeIndex)) return;
return check(node, index, valueNode);
});
if (needsFix) {
setDeclarationValue(node, parsedValue.toString());
}
}
root.walkAtRules(checkAtRule);
root.walkDecls(checkDecl);
};
}
function isLineHeightValue({ prop }, nodes, index) {
return (
prop.toLowerCase() === 'font' &&
index > 0 &&
nodes[index - 1].type === 'div' &&
nodes[index - 1].value === '/'
);
}
function isLineHeight(prop) {
return prop.toLowerCase() === 'line-height';
}
function isWord({ type }) {
return type === 'word';
}
function isLength(unit) {
return keywordSets.lengthUnits.has(unit.toLowerCase());
}
function isFraction(unit) {
return unit.toLowerCase() === 'fr';
}
function isZero(number) {
return Number.parseFloat(number) === 0;
}
rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;