mirror of
https://github.com/snachodog/just-the-docs.git
synced 2025-09-13 13:23:32 -06:00
Initial commit
This commit is contained in:
103
node_modules/stylelint/lib/rules/function-url-quotes/README.md
generated
vendored
Normal file
103
node_modules/stylelint/lib/rules/function-url-quotes/README.md
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
# function-url-quotes
|
||||
|
||||
Require or disallow quotes for urls.
|
||||
|
||||
```css
|
||||
a { background: url("x.jpg") }
|
||||
/** ↑ ↑
|
||||
* These quotes */
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
`string`: `"always"|"never"`
|
||||
|
||||
### `"always"`
|
||||
|
||||
Urls *must always* be quoted.
|
||||
|
||||
The following patterns are considered warnings:
|
||||
|
||||
```css
|
||||
@import url(foo.css);
|
||||
```
|
||||
|
||||
```css
|
||||
@document domain(http://www.w3.org/);
|
||||
```
|
||||
|
||||
```css
|
||||
@font-face { font-family: 'foo'; src: url(foo.ttf); }
|
||||
```
|
||||
|
||||
```css
|
||||
@-moz-document url-prefix() {}
|
||||
```
|
||||
|
||||
The following patterns are *not* considered warnings:
|
||||
|
||||
```css
|
||||
a { background: url('x.jpg'); }
|
||||
```
|
||||
|
||||
```css
|
||||
@import url("foo.css");
|
||||
```
|
||||
|
||||
```css
|
||||
@document domain('http://www.w3.org/');
|
||||
```
|
||||
|
||||
```css
|
||||
@font-face { font-family: "foo"; src: url("foo.ttf"); }
|
||||
```
|
||||
|
||||
```css
|
||||
@-moz-document url-prefix('') {}
|
||||
```
|
||||
|
||||
### `"never"`
|
||||
|
||||
Urls *must never* be quoted.
|
||||
|
||||
The following patterns are considered warnings:
|
||||
|
||||
```css
|
||||
a { background: url('x.jpg'); }
|
||||
```
|
||||
|
||||
```css
|
||||
@import url("foo.css");
|
||||
```
|
||||
|
||||
```css
|
||||
@font-face { font-family: "foo"; src: url('foo.ttf'); }
|
||||
```
|
||||
|
||||
The following patterns are *not* considered warnings:
|
||||
|
||||
```css
|
||||
a { background: url(x.jpg); }
|
||||
```
|
||||
|
||||
```css
|
||||
@import url(foo.css);
|
||||
```
|
||||
|
||||
```css
|
||||
@font-face { font-family: 'foo'; src: url(foo.ttf); }
|
||||
```
|
||||
|
||||
## Optional secondary options
|
||||
|
||||
### `except: ["empty"]`
|
||||
|
||||
Reverse the primary option if the function has no arguments.
|
||||
|
||||
For example, with `"always"`.
|
||||
|
||||
The following pattern is *not* considered warnings:
|
||||
|
||||
```css
|
||||
@-moz-document url-prefix() {}
|
||||
```
|
113
node_modules/stylelint/lib/rules/function-url-quotes/index.js
generated
vendored
Normal file
113
node_modules/stylelint/lib/rules/function-url-quotes/index.js
generated
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
"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 _ = require("lodash")
|
||||
|
||||
const ruleName = "function-url-quotes"
|
||||
|
||||
const messages = ruleMessages(ruleName, {
|
||||
expected: () => "Expected quotes",
|
||||
rejected: () => "Unexpected quotes",
|
||||
})
|
||||
|
||||
const rule = function (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(checkStatement)
|
||||
root.walkRules(checkStatement)
|
||||
|
||||
function checkStatement(statement) {
|
||||
if (statement.type === "atrule") {
|
||||
checkAtRuleParams(statement)
|
||||
}
|
||||
|
||||
statement.walkDecls(function (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.trimLeft()
|
||||
if (!isStandardSyntaxUrl(leftTrimmedArgs)) {
|
||||
return
|
||||
}
|
||||
const complaintIndex = index + args.length - leftTrimmedArgs.length
|
||||
const hasQuotes = leftTrimmedArgs[0] === "'" || leftTrimmedArgs[0] === "\""
|
||||
|
||||
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
|
Reference in New Issue
Block a user