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
+120
View File
@@ -0,0 +1,120 @@
# function-url-quotes
Require or disallow quotes for urls.
<!-- prettier-ignore -->
```css
a { background: url("x.jpg") }
/** ↑ ↑
* These quotes */
```
## Options
`string`: `"always"|"never"`
### `"always"`
Urls _must always_ be quoted.
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
@import url(foo.css);
```
<!-- prettier-ignore -->
```css
@document domain(http://www.w3.org/);
```
<!-- prettier-ignore -->
```css
@font-face { font-family: 'foo'; src: url(foo.ttf); }
```
<!-- prettier-ignore -->
```css
@-moz-document url-prefix() {}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a { background: url('x.jpg'); }
```
<!-- prettier-ignore -->
```css
@import url("foo.css");
```
<!-- prettier-ignore -->
```css
@document domain('http://www.w3.org/');
```
<!-- prettier-ignore -->
```css
@font-face { font-family: "foo"; src: url("foo.ttf"); }
```
<!-- prettier-ignore -->
```css
@-moz-document url-prefix('') {}
```
### `"never"`
Urls _must never_ be quoted.
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a { background: url('x.jpg'); }
```
<!-- prettier-ignore -->
```css
@import url("foo.css");
```
<!-- prettier-ignore -->
```css
@font-face { font-family: "foo"; src: url('foo.ttf'); }
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a { background: url(x.jpg); }
```
<!-- prettier-ignore -->
```css
@import url(foo.css);
```
<!-- prettier-ignore -->
```css
@font-face { font-family: 'foo'; src: url(foo.ttf); }
```
## Optional secondary options
### `except: ["empty"]`
Reverse the primary option for functions that have no arguments.
For example, with `"always"`.
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
@-moz-document url-prefix() {}
```
+113
View File
@@ -0,0 +1,113 @@
// @ts-nocheck
'use strict';
const atRuleParamIndex = require('../../utils/atRuleParamIndex');
const functionArgumentsSearch = require('../../utils/functionArgumentsSearch');
const isStandardSyntaxUrl = require('../../utils/isStandardSyntaxUrl');
const optionsMatches = require('../../utils/optionsMatches');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');
const ruleName = 'function-url-quotes';
const messages = ruleMessages(ruleName, {
expected: () => 'Expected quotes',
rejected: () => 'Unexpected quotes',
});
function rule(expectation, options) {
return (root, result) => {
const validOptions = validateOptions(
result,
ruleName,
{
actual: expectation,
possible: ['always', 'never'],
},
{
actual: options,
possible: {
except: ['empty'],
},
optional: true,
},
);
if (!validOptions) {
return;
}
root.walkAtRules(checkAtRuleParams);
root.walkDecls(checkDeclParams);
function checkDeclParams(decl) {
functionArgumentsSearch(decl.toString().toLowerCase(), 'url', (args, index) => {
checkArgs(args, decl, index, 'url');
});
}
function checkAtRuleParams(atRule) {
const atRuleParamsLowerCase = atRule.params.toLowerCase();
functionArgumentsSearch(atRuleParamsLowerCase, 'url', (args, index) => {
checkArgs(args, atRule, index + atRuleParamIndex(atRule), 'url');
});
functionArgumentsSearch(atRuleParamsLowerCase, 'url-prefix', (args, index) => {
checkArgs(args, atRule, index + atRuleParamIndex(atRule), 'url-prefix');
});
functionArgumentsSearch(atRuleParamsLowerCase, 'domain', (args, index) => {
checkArgs(args, atRule, index + atRuleParamIndex(atRule), 'domain');
});
}
function checkArgs(args, node, index, functionName) {
let shouldHasQuotes = expectation === 'always';
const leftTrimmedArgs = args.trimStart();
if (!isStandardSyntaxUrl(leftTrimmedArgs)) {
return;
}
const complaintIndex = index + args.length - leftTrimmedArgs.length;
const hasQuotes = leftTrimmedArgs.startsWith("'") || leftTrimmedArgs.startsWith('"');
const trimmedArg = args.trim();
const isEmptyArgument = ['', "''", '""'].includes(trimmedArg);
if (optionsMatches(options, 'except', 'empty') && isEmptyArgument) {
shouldHasQuotes = !shouldHasQuotes;
}
if (shouldHasQuotes) {
if (hasQuotes) {
return;
}
complain(messages.expected(functionName), node, complaintIndex);
} else {
if (!hasQuotes) {
return;
}
complain(messages.rejected(functionName), node, complaintIndex);
}
}
function complain(message, node, index) {
report({
message,
node,
index,
result,
ruleName,
});
}
};
}
rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;