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
+21
View File
@@ -0,0 +1,21 @@
# linebreaks
Specify unix or windows linebreaks.
The [`fix` option](../../../docs/user-guide/usage/options.md#fix) can automatically fix all of the problems reported by this rule.
## Options
`string`: `"unix"|"windows"`
### `"unix"`
Linebreaks _must always_ be LF (`\n`).
Lines with CRLF linebreaks are considered violations.
### `"windows"`
Linebreaks _must always_ be CRLF (`\r\n`).
Lines with LF linebreaks are considered violations.
+102
View File
@@ -0,0 +1,102 @@
// @ts-nocheck
'use strict';
const _ = require('lodash');
const postcss = require('postcss');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');
const ruleName = 'linebreaks';
const messages = ruleMessages(ruleName, {
expected: (linebreak) => `Expected linebreak to be ${linebreak}`,
});
function rule(actual, secondary, context) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, {
actual,
possible: ['unix', 'windows'],
});
if (!validOptions) {
return;
}
const shouldHaveCR = actual === 'windows';
if (context.fix) {
const propertiesToUpdate = ['selector', 'raws.before', 'raws.after', 'value', 'text'];
root.walk((node) => {
propertiesToUpdate.forEach((property) => {
const fixedData = fixData(_.get(node, property));
_.set(node, property, fixedData);
});
});
root.raws.after = fixData(root.raws.after);
} else {
const lines = root.source.input.css.split('\n');
for (let i = 0; i < lines.length; i++) {
let line = lines[i];
if (i < lines.length - 1 && !line.includes('\r')) {
line += '\n';
}
if (hasError(line)) {
const lineNum = i + 1;
const colNum = line.length;
reportNewlineError(lineNum, colNum);
}
}
}
function hasError(dataToCheck) {
const hasNewlineToVerify = /[\r\n]/.test(dataToCheck);
const hasCR = hasNewlineToVerify ? /\r/.test(dataToCheck) : false;
return hasNewlineToVerify && hasCR !== shouldHaveCR;
}
function fixData(data) {
if (data) {
let res = data.replace(/\r/g, '');
if (shouldHaveCR) {
res = res.replace(/\n/g, '\r\n');
}
return res;
}
return data;
}
function reportNewlineError(line, column) {
// Creating a node manually helps us to point to empty lines.
const node = postcss.rule({
source: {
start: { line, column },
},
});
report({
message: messages.expected(actual),
node,
result,
ruleName,
});
}
};
}
rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;