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
+181
View File
@@ -0,0 +1,181 @@
# function-name-case
Specify lowercase or uppercase for function names.
<!-- prettier-ignore -->
```css
a { width: calc(5% - 10em); }
/** ↑
* This function */
```
Camel case function names, e.g. `translateX`, are accounted for when the `lower` option is used.
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 {
width: Calc(5% - 10em);
}
```
<!-- prettier-ignore -->
```css
a {
width: cAlC(5% - 10em);
}
```
<!-- prettier-ignore -->
```css
a {
width: CALC(5% - 10em);
}
```
<!-- prettier-ignore -->
```css
a {
background: -WEBKIT-RADIAL-GRADIENT(red, green, blue);
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
width: calc(5% - 10em);
}
```
<!-- prettier-ignore -->
```css
a {
background: -webkit-radial-gradient(red, green, blue);
}
```
### `"upper"`
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
width: Calc(5% - 10em);
}
```
<!-- prettier-ignore -->
```css
a {
width: cAlC(5% - 10em);
}
```
<!-- prettier-ignore -->
```css
a {
width: calc(5% - 10em);
}
```
<!-- prettier-ignore -->
```css
a {
background: -webkit-radial-gradient(red, green, blue);
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
width: CALC(5% - 10em);
}
```
<!-- prettier-ignore -->
```css
a {
background: -WEBKIT-RADIAL-GRADIENT(red, green, blue);
}
```
## Optional secondary options
### `ignoreFunctions: ["/regex-as-string/", /regex/, "non-regex"]`
Ignore case of function names.
For example, with `"lower"`.
Given:
```
["some-function", "/^get.*$/"]
```
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
color: sOmE-FuNcTiOn();
}
```
<!-- prettier-ignore -->
```css
a {
color: some-other-function();
}
```
<!-- prettier-ignore -->
```css
a {
color: GetColor();
}
```
<!-- prettier-ignore -->
```css
a {
color: GET_COLOR();
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
display: some-function();
}
```
<!-- prettier-ignore -->
```css
a {
display: getColor();
}
```
<!-- prettier-ignore -->
```css
a {
display: get_color();
}
```
+111
View File
@@ -0,0 +1,111 @@
// @ts-nocheck
'use strict';
const _ = require('lodash');
const declarationValueIndex = require('../../utils/declarationValueIndex');
const getDeclarationValue = require('../../utils/getDeclarationValue');
const isStandardSyntaxFunction = require('../../utils/isStandardSyntaxFunction');
const keywordSets = require('../../reference/keywordSets');
const matchesStringOrRegExp = require('../../utils/matchesStringOrRegExp');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const setDeclarationValue = require('../../utils/setDeclarationValue');
const validateOptions = require('../../utils/validateOptions');
const valueParser = require('postcss-value-parser');
const ruleName = 'function-name-case';
const messages = ruleMessages(ruleName, {
expected: (actual, expected) => `Expected "${actual}" to be "${expected}"`,
});
const mapLowercaseFunctionNamesToCamelCase = new Map();
keywordSets.camelCaseFunctionNames.forEach((func) => {
mapLowercaseFunctionNamesToCamelCase.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: {
ignoreFunctions: [_.isString, _.isRegExp],
},
optional: true,
},
);
if (!validOptions) {
return;
}
root.walkDecls((decl) => {
let needFix = false;
const parsed = valueParser(getDeclarationValue(decl));
parsed.walk((node) => {
if (node.type !== 'function' || !isStandardSyntaxFunction(node)) {
return;
}
const functionName = node.value;
const functionNameLowerCase = functionName.toLowerCase();
const ignoreFunctions = (options && options.ignoreFunctions) || [];
if (ignoreFunctions.length > 0 && matchesStringOrRegExp(functionName, ignoreFunctions)) {
return;
}
let expectedFunctionName = null;
if (
expectation === 'lower' &&
mapLowercaseFunctionNamesToCamelCase.has(functionNameLowerCase)
) {
expectedFunctionName = mapLowercaseFunctionNamesToCamelCase.get(functionNameLowerCase);
} else if (expectation === 'lower') {
expectedFunctionName = functionNameLowerCase;
} else {
expectedFunctionName = functionName.toUpperCase();
}
if (functionName === expectedFunctionName) {
return;
}
if (context.fix) {
needFix = true;
node.value = expectedFunctionName;
return;
}
report({
message: messages.expected(functionName, expectedFunctionName),
node: decl,
index: declarationValueIndex(decl) + node.sourceIndex,
result,
ruleName,
});
});
if (context.fix && needFix) {
setDeclarationValue(decl, parsed.toString());
}
});
};
}
rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;