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
+320
View File
@@ -0,0 +1,320 @@
# value-keyword-case
Specify lowercase or uppercase for keywords values.
<!-- prettier-ignore -->
```css
a { display: block; }
/** ↑
* These values */
```
This rule ignores [`<custom-idents>`](https://developer.mozilla.org/en/docs/Web/CSS/custom-ident) of known properties. Keyword values which are paired with non-properties (e.g. `$vars` and custom properties), and do not conform to the primary option, can be ignored using the `ignoreKeywords: []` secondary option.
The [`fix` option](../../../docs/user-guide/usage/options.md#fix) can automatically fix all of the problems reported by this rule.
## Options
`string`: `"lower"|"upper"`
### `"lower"`
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
display: Block;
}
```
<!-- prettier-ignore -->
```css
a {
display: bLoCk;
}
```
<!-- prettier-ignore -->
```css
a {
display: BLOCK;
}
```
<!-- prettier-ignore -->
```css
a {
transition: -WEBKIT-TRANSFORM 2s;
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
display: block;
}
```
<!-- prettier-ignore -->
```css
a {
transition: -webkit-transform 2s;
}
```
### `"upper"`
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
display: Block;
}
```
<!-- prettier-ignore -->
```css
a {
display: bLoCk;
}
```
<!-- prettier-ignore -->
```css
a {
display: block;
}
```
<!-- prettier-ignore -->
```css
a {
transition: -webkit-transform 2s;
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
display: BLOCK;
}
```
<!-- prettier-ignore -->
```css
a {
transition: -WEBKIT-TRANSFORM 2s;
}
```
## Optional secondary options
### `ignoreKeywords: ["/regex/", /regex/, "non-regex"]`
Ignore case of keywords values.
For example, with `"lower"`.
Given:
```
["Block", "/^(f|F)lex$/"]
```
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
display: bLoCk;
}
```
<!-- prettier-ignore -->
```css
a {
display: BLOCK;
}
```
<!-- prettier-ignore -->
```css
a {
display: fLeX;
}
```
<!-- prettier-ignore -->
```css
a {
display: FLEX;
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
display: block;
}
```
<!-- prettier-ignore -->
```css
a {
display: Block;
}
```
<!-- prettier-ignore -->
```css
a {
display: flex;
}
```
<!-- prettier-ignore -->
```css
a {
display: Flex;
}
```
### `ignoreProperties: ["/regex/", /regex/, "non-regex"]`
Ignore case of the values of the listed properties.
For example, with `"lower"`.
```js
["/^(b|B)ackground$/", "display"];
```
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
text-align: LEFT;
}
```
<!-- prettier-ignore -->
```css
a {
text-align: Left;
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
display: bloCk;
}
```
<!-- prettier-ignore -->
```css
a {
display: BloCk;
}
```
<!-- prettier-ignore -->
```css
a {
display: BLOCK;
}
```
<!-- prettier-ignore -->
```css
a {
display: block;
}
```
<!-- prettier-ignore -->
```css
a {
background: Red;
}
```
<!-- prettier-ignore -->
```css
a {
Background: deepPink;
}
```
### `ignoreFunctions: ["/regex/", /regex/, "non-regex"]`
Ignore case of the values inside the listed functions.
For example, with `"upper"`.
```js
["/^(f|F)oo$/", "t"];
```
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
display: b(inline);
}
```
```css
a {
color: bar(--camelCase);
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
display: t(flex);
}
```
<!-- prettier-ignore -->
```css
a {
display: t(fLeX);
}
```
<!-- prettier-ignore -->
```css
a {
color: t(--camelCase);
}
```
<!-- prettier-ignore -->
```css
a {
color: foo(--camelCase);
}
```
<!-- prettier-ignore -->
```css
a {
color: Foo(--camelCase);
}
```
+236
View File
@@ -0,0 +1,236 @@
// @ts-nocheck
'use strict';
const _ = require('lodash');
const declarationValueIndex = require('../../utils/declarationValueIndex');
const getDeclarationValue = require('../../utils/getDeclarationValue');
const getUnitFromValueNode = require('../../utils/getUnitFromValueNode');
const isCounterIncrementCustomIdentValue = require('../../utils/isCounterIncrementCustomIdentValue');
const isCounterResetCustomIdentValue = require('../../utils/isCounterResetCustomIdentValue');
const isStandardSyntaxValue = require('../../utils/isStandardSyntaxValue');
const keywordSets = require('../../reference/keywordSets');
const matchesStringOrRegExp = require('../../utils/matchesStringOrRegExp');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');
const valueParser = require('postcss-value-parser');
const ruleName = 'value-keyword-case';
const messages = ruleMessages(ruleName, {
expected: (actual, expected) => `Expected "${actual}" to be "${expected}"`,
});
// Operators are interpreted as "words" by the value parser, so we want to make sure to ignore them.
const ignoredCharacters = new Set(['+', '-', '/', '*', '%']);
const gridRowProps = new Set(['grid-row', 'grid-row-start', 'grid-row-end']);
const gridColumnProps = new Set(['grid-column', 'grid-column-start', 'grid-column-end']);
const mapLowercaseKeywordsToCamelCase = new Map();
keywordSets.camelCaseKeywords.forEach((func) => {
mapLowercaseKeywordsToCamelCase.set(func.toLowerCase(), func);
});
function rule(expectation, options, context) {
return (root, result) => {
const validOptions = validateOptions(
result,
ruleName,
{
actual: expectation,
possible: ['lower', 'upper'],
},
{
actual: options,
possible: {
ignoreProperties: [_.isString, _.isRegExp],
ignoreKeywords: [_.isString, _.isRegExp],
ignoreFunctions: [_.isString, _.isRegExp],
},
optional: true,
},
);
if (!validOptions) {
return;
}
root.walkDecls((decl) => {
const prop = decl.prop;
const propLowerCase = decl.prop.toLowerCase();
const value = decl.value;
const parsed = valueParser(getDeclarationValue(decl));
let needFix = false;
parsed.walk((node) => {
const valueLowerCase = node.value.toLowerCase();
// Ignore system colors
if (keywordSets.systemColors.has(valueLowerCase)) {
return;
}
// Ignore keywords within `url` and `var` function
if (
node.type === 'function' &&
(valueLowerCase === 'url' ||
valueLowerCase === 'var' ||
valueLowerCase === 'counter' ||
valueLowerCase === 'counters' ||
valueLowerCase === 'attr')
) {
return false;
}
// ignore keywords within ignoreFunctions functions
const ignoreFunctions = (options && options.ignoreFunctions) || [];
if (
node.type === 'function' &&
ignoreFunctions.length > 0 &&
matchesStringOrRegExp(valueLowerCase, ignoreFunctions)
) {
return false;
}
const keyword = node.value;
// Ignore css variables, and hex values, and math operators, and sass interpolation
if (
node.type !== 'word' ||
!isStandardSyntaxValue(node.value) ||
value.includes('#') ||
ignoredCharacters.has(keyword) ||
getUnitFromValueNode(node)
) {
return;
}
if (
propLowerCase === 'animation' &&
!keywordSets.animationShorthandKeywords.has(valueLowerCase) &&
!keywordSets.animationNameKeywords.has(valueLowerCase)
) {
return;
}
if (
propLowerCase === 'animation-name' &&
!keywordSets.animationNameKeywords.has(valueLowerCase)
) {
return;
}
if (
propLowerCase === 'font' &&
!keywordSets.fontShorthandKeywords.has(valueLowerCase) &&
!keywordSets.fontFamilyKeywords.has(valueLowerCase)
) {
return;
}
if (
propLowerCase === 'font-family' &&
!keywordSets.fontFamilyKeywords.has(valueLowerCase)
) {
return;
}
if (
propLowerCase === 'counter-increment' &&
isCounterIncrementCustomIdentValue(valueLowerCase)
) {
return;
}
if (propLowerCase === 'counter-reset' && isCounterResetCustomIdentValue(valueLowerCase)) {
return;
}
if (gridRowProps.has(propLowerCase) && !keywordSets.gridRowKeywords.has(valueLowerCase)) {
return;
}
if (
gridColumnProps.has(propLowerCase) &&
!keywordSets.gridColumnKeywords.has(valueLowerCase)
) {
return;
}
if (propLowerCase === 'grid-area' && !keywordSets.gridAreaKeywords.has(valueLowerCase)) {
return;
}
if (
propLowerCase === 'list-style' &&
!keywordSets.listStyleShorthandKeywords.has(valueLowerCase) &&
!keywordSets.listStyleTypeKeywords.has(valueLowerCase)
) {
return;
}
if (
propLowerCase === 'list-style-type' &&
!keywordSets.listStyleTypeKeywords.has(valueLowerCase)
) {
return;
}
const ignoreKeywords = (options && options.ignoreKeywords) || [];
const ignoreProperties = (options && options.ignoreProperties) || [];
if (ignoreKeywords.length > 0 && matchesStringOrRegExp(keyword, ignoreKeywords)) {
return;
}
if (ignoreProperties.length > 0 && matchesStringOrRegExp(prop, ignoreProperties)) {
return;
}
const keywordLowerCase = keyword.toLocaleLowerCase();
let expectedKeyword = null;
if (expectation === 'lower' && mapLowercaseKeywordsToCamelCase.has(keywordLowerCase)) {
expectedKeyword = mapLowercaseKeywordsToCamelCase.get(keywordLowerCase);
} else if (expectation === 'lower') {
expectedKeyword = keyword.toLowerCase();
} else {
expectedKeyword = keyword.toUpperCase();
}
if (keyword === expectedKeyword) {
return;
}
if (context.fix) {
needFix = true;
node.value = expectedKeyword;
return;
}
report({
message: messages.expected(keyword, expectedKeyword),
node: decl,
index: declarationValueIndex(decl) + node.sourceIndex,
result,
ruleName,
});
});
if (context.fix && needFix) {
decl.value = parsed.toString();
}
});
};
}
rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;