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
+73
View File
@@ -0,0 +1,73 @@
# string-no-newline
Disallow (unescaped) newlines in strings.
<!-- prettier-ignore -->
```css
a {
content: "first
second"; ↑
} ↑
/** ↑
* The newline here */
```
[The spec](https://www.w3.org/TR/CSS2/syndata.html#strings) says this: "A string cannot directly contain a newline. To include a newline in a string, use an escape representing the line feed character in ISO-10646 (U+000A), such as '\A' or '\00000a'." And also: "It is possible to break strings over several lines, for aesthetic or other reasons, but in such a case the newline itself has to be escaped with a backslash (\\)."
## Options
### `true`
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a {
content: "first
second";
}
```
<!-- prettier-ignore -->
```css
[title="something
is probably wrong"] {}
```
<!-- prettier-ignore -->
```css
a {
font-family: "Times
New
Roman";
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
content: "first\Asecond";
}
```
<!-- prettier-ignore -->
```css
a {
content: "first\\nsecond";
}
```
<!-- prettier-ignore -->
```css
[title="nothing\
is wrong"] {}
```
<!-- prettier-ignore -->
```css
a {
font-family: "Times New Roman";
}
```
+115
View File
@@ -0,0 +1,115 @@
// @ts-nocheck
'use strict';
const atRuleParamIndex = require('../../utils/atRuleParamIndex');
const declarationValueIndex = require('../../utils/declarationValueIndex');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
const parseSelector = require('../../utils/parseSelector');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');
const valueParser = require('postcss-value-parser');
const ruleName = 'string-no-newline';
const reNewLine = /(\r?\n)/;
const messages = ruleMessages(ruleName, {
rejected: 'Unexpected newline in string',
});
function rule(actual) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, { actual });
if (!validOptions) {
return;
}
root.walk((node) => {
switch (node.type) {
case 'atrule':
checkDeclOrAtRule(node, node.params, atRuleParamIndex);
break;
case 'decl':
checkDeclOrAtRule(node, node.value, declarationValueIndex);
break;
case 'rule':
checkRule(node);
break;
}
});
function checkRule(ruleNode) {
// Get out quickly if there are no new line
if (!reNewLine.test(ruleNode.selector)) {
return;
}
if (!isStandardSyntaxSelector(ruleNode.selector)) {
return;
}
parseSelector(ruleNode.selector, result, ruleNode, (selectorTree) => {
selectorTree.walkAttributes((attributeNode) => {
if (!reNewLine.test(attributeNode.value)) {
return;
}
const openIndex = [
// length of our attribute
attributeNode.attribute,
// length of our operator , ie '='
attributeNode.operator,
// length of the contents before newline
RegExp.leftContext,
].reduce(
(index, str) => index + str.length,
// index of the start of our attribute node in our source
attributeNode.sourceIndex,
);
report({
message: messages.rejected,
node: ruleNode,
index: openIndex,
result,
ruleName,
});
});
});
}
function checkDeclOrAtRule(node, value, getIndex) {
// Get out quickly if there are no new line
if (!reNewLine.test(value)) {
return;
}
valueParser(value).walk((valueNode) => {
if (valueNode.type !== 'string' || !reNewLine.test(valueNode.value)) {
return;
}
const openIndex = [
// length of the quote
valueNode.quote,
// length of the contents before newline
RegExp.leftContext,
].reduce((index, str) => index + str.length, valueNode.sourceIndex);
report({
message: messages.rejected,
node,
index: getIndex(node) + openIndex,
result,
ruleName,
});
});
}
};
}
rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;