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
+151
View File
@@ -0,0 +1,151 @@
# max-line-length
Limit the length of a line.
<!-- prettier-ignore -->
```css
a { color: red }
/** ↑
* The end */
```
Lines that exceed the maximum length but contain no whitespace (other than at the beginning of the line) are ignored.
When evaluating the line length, the arguments of any `url(...)` functions are excluded from the calculation, because typically you have no control over the length of these arguments. This means that long `url()` functions should not contribute to violations.
## Options
`int`: Maximum number of characters allowed.
For example, with `20`:
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a { color: 0; top: 0; }
```
<!-- prettier-ignore -->
```css
a {
background: linear-gradient(red, blue);
}
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a {
color: 0;
top: 0;
}
```
<!-- prettier-ignore -->
```css
a {
background: url(a-url-that-is-over-20-characters-long);
}
```
## Optional secondary options
### `ignore: ["non-comments"]`
Only enforce the line-length limit for lines within comments.
This does not apply to comments that are stuck in between other stuff, only to lines that begin at the beginning or in the middle of a comment.
For example, with a maximum length of `30`.
The following patterns are considered violations:
Each have only one violation.
<!-- prettier-ignore -->
```css
/* This line is too long for my rule */
a { color: pink; background: orange; }
a { color: pink; /* this comment is also long but not on its own line */ }
```
<!-- prettier-ignore -->
```css
a { color: pink; background: orange; }
/**
* This line is short,
* but this line is too long for my liking,
* though this one is fine
*/
a { color: pink; /* this comment is also long but not on its own line */ }
```
### `ignore: ["comments"]`
Only enforce the line-length limit for lines that are not comments.
This also applies to comments that are between code on the same line.
For example, with a maximum length of `30`.
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a { color: pink; } /* comment that is too long */
```
<!-- prettier-ignore -->
```css
a { /* this comment is too long for the max length */ }
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
/* comment that is too long for my rule*/
a { color: pink; }
```
<!-- prettier-ignore -->
```css
/*
* comment that is too long the max length
* comment that is too long the max length
*
*/
a { color: pink; }
```
### `ignorePattern: "/regex/"`
Ignore any line that matches the given regex pattern, regardless of whether it is comment or not. The regex may be passed as a string (for JSON configuration) by enclosing in forward-slashes, or an ordinary JavaScript RegExp may be used.
Given:
```
"/^@import\\s+/"
```
The following pattern is _not_ considered a violation:
<!-- prettier-ignore -->
```css
@import "../../../../another/css/or/scss/file/or/something.css";
```
Given the following, with a maximum length of `20`.
```js
["/https?://[0-9,a-z]*.*/"];
```
The following pattern is _not_ considered a violation:
<!-- prettier-ignore -->
```css
/* ignore urls https://www.example.com */
```
+183
View File
@@ -0,0 +1,183 @@
// @ts-nocheck
'use strict';
const _ = require('lodash');
const execall = require('execall');
const optionsMatches = require('../../utils/optionsMatches');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const styleSearch = require('style-search');
const validateOptions = require('../../utils/validateOptions');
const ruleName = 'max-line-length';
const EXCLUDED_PATTERNS = [
/url\(\s*(\S.*\S)\s*\)/gi, // allow tab, whitespace in url content
/@import\s+(['"].*['"])/gi,
];
const messages = ruleMessages(ruleName, {
expected: (max) =>
`Expected line length to be no more than ${max} ${max === 1 ? 'character' : 'characters'}`,
});
function rule(maxLength, options, context) {
return (root, result) => {
const validOptions = validateOptions(
result,
ruleName,
{
actual: maxLength,
possible: _.isNumber,
},
{
actual: options,
possible: {
ignore: ['non-comments', 'comments'],
ignorePattern: [_.isString, _.isRegExp],
},
optional: true,
},
);
if (!validOptions) {
return;
}
const ignoreNonComments = optionsMatches(options, 'ignore', 'non-comments');
const ignoreComments = optionsMatches(options, 'ignore', 'comments');
const rootString = context.fix ? root.toString() : root.source.input.css;
// Array of skipped sub strings, i.e `url(...)`, `@import "..."`
let skippedSubStrings = [];
let skippedSubStringsIndex = 0;
EXCLUDED_PATTERNS.forEach((pattern) =>
execall(pattern, rootString).forEach((match) => {
const startOfSubString =
match.index + match.match.indexOf(_.get(match, 'subMatches[0]', ''));
return skippedSubStrings.push([
startOfSubString,
startOfSubString + _.get(match, 'subMatches[0].length', 0),
]);
}),
);
skippedSubStrings = skippedSubStrings.sort((a, b) => a[0] - b[0]);
// Check first line
checkNewline({ endIndex: 0 });
// Check subsequent lines
styleSearch({ source: rootString, target: ['\n'], comments: 'check' }, (match) =>
checkNewline(match),
);
function complain(index) {
report({
index,
result,
ruleName,
message: messages.expected(maxLength),
node: root,
});
}
function tryToPopSubString(start, end) {
const [startSubString, endSubString] = skippedSubStrings[skippedSubStringsIndex];
// Excluded substring does not presented in current line
if (end < startSubString) {
return 0;
}
// Compute excluded substring size regarding to current line indexes
const excluded = Math.min(end, endSubString) - Math.max(start, startSubString);
// Current substring is out of range for next lines
if (endSubString <= end) {
skippedSubStringsIndex++;
}
return excluded;
}
function checkNewline(match) {
let nextNewlineIndex = rootString.indexOf('\n', match.endIndex);
if (rootString[nextNewlineIndex - 1] === '\r') {
nextNewlineIndex -= 1;
}
// Accommodate last line
if (nextNewlineIndex === -1) {
nextNewlineIndex = rootString.length;
}
const rawLineLength = nextNewlineIndex - match.endIndex;
const excludedLength = skippedSubStrings[skippedSubStringsIndex]
? tryToPopSubString(match.endIndex, nextNewlineIndex)
: 0;
const lineText = rootString.slice(match.endIndex, nextNewlineIndex);
// Case sensitive ignorePattern match
if (optionsMatches(options, 'ignorePattern', lineText)) {
return;
}
// If the line's length is less than or equal to the specified
// max, ignore it ... So anything below is liable to be complained about.
// **Note that the length of any url arguments or import urls
// are excluded from the calculation.**
if (rawLineLength - excludedLength <= maxLength) {
return;
}
const complaintIndex = nextNewlineIndex - 1;
if (ignoreComments) {
if (match.insideComment) {
return;
}
// This trimming business is to notice when the line starts a
// comment but that comment is indented, e.g.
// /* something here */
const nextTwoChars = rootString.slice(match.endIndex).trim().slice(0, 2);
if (nextTwoChars === '/*' || nextTwoChars === '//') {
return;
}
}
if (ignoreNonComments) {
if (match.insideComment) {
return complain(complaintIndex);
}
// This trimming business is to notice when the line starts a
// comment but that comment is indented, e.g.
// /* something here */
const nextTwoChars = rootString.slice(match.endIndex).trim().slice(0, 2);
if (nextTwoChars !== '/*' && nextTwoChars !== '//') {
return;
}
return complain(complaintIndex);
}
// If there are no spaces besides initial (indent) spaces, ignore it
const lineString = rootString.slice(match.endIndex, nextNewlineIndex);
if (!lineString.replace(/^\s+/, '').includes(' ')) {
return;
}
return complain(complaintIndex);
}
};
}
rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;