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
+50
View File
@@ -0,0 +1,50 @@
# named-grid-areas-no-invalid
Disallow invalid named grid areas.
<!-- prettier-ignore -->
```css
a { grid-template-areas:
"a a a"
"b b b"; }
/** ↑
* This named grid area */
```
For a named grid area to be valid, all strings must define:
- the same number of cell tokens
- at least one cell token
And all named grid areas that spans multiple grid cells must form a single filled-in rectangle.
## Options
### `true`
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a { grid-template-areas: "" }
```
<!-- prettier-ignore -->
```css
a { grid-template-areas: "a a a"
"b b b b"; }
```
<!-- prettier-ignore -->
```css
a { grid-template-areas: "a a a"
"b b a"; }
```
The following pattern is _not_ considered a violation:
<!-- prettier-ignore -->
```css
a { grid-template-areas: "a a a"
"b b b"; }
```
+80
View File
@@ -0,0 +1,80 @@
// @ts-nocheck
'use strict';
const _ = require('lodash');
const declarationValueIndex = require('../../utils/declarationValueIndex');
const findNotContiguousOrRectangular = require('./utils/findNotContiguousOrRectangular');
const isRectangular = require('./utils/isRectangular');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');
const valueParser = require('postcss-value-parser');
const ruleName = 'named-grid-areas-no-invalid';
const messages = ruleMessages(ruleName, {
expectedToken: () => 'Expected cell token within string',
expectedSameNumber: () => 'Expected same number of cell tokens in each string',
expectedRectangle: (name) => `Expected single filled-in rectangle for "${name}"`,
});
function rule(actual) {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, { actual });
if (!validOptions) {
return;
}
root.walkDecls(/^grid-template-areas$/i, (decl) => {
const { value } = decl;
if (value.toLowerCase().trim() === 'none') return;
const areas = [];
let reportSent = false;
valueParser(value).walk(({ sourceIndex, type, value: tokenValue }) => {
if (type !== 'string') return;
if (tokenValue === '') {
complain(messages.expectedToken(), sourceIndex);
reportSent = true;
return;
}
areas.push(_.compact(tokenValue.trim().split(' ')));
});
if (reportSent) return;
if (!isRectangular(areas)) {
complain(messages.expectedSameNumber());
return;
}
const notContiguousOrRectangular = findNotContiguousOrRectangular(areas);
notContiguousOrRectangular.sort().forEach((name) => {
complain(messages.expectedRectangle(name));
});
function complain(message, sourceIndex = 0) {
report({
message,
node: decl,
index: declarationValueIndex(decl) + sourceIndex,
result,
ruleName,
});
}
});
};
}
rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;
@@ -0,0 +1,61 @@
'use strict';
const _ = require('lodash');
/**
*
* @param {string[][]} areas
* @param {string} name
* @returns {boolean}
*/
function isContiguousAndRectangular(areas, name) {
const indicesByRow = areas.map((row) => {
const indices = [];
let idx = row.indexOf(name);
while (idx !== -1) {
indices.push(idx);
idx = row.indexOf(name, idx + 1);
}
return indices;
});
for (let i = 0; i < indicesByRow.length; i++) {
for (let j = i + 1; j < indicesByRow.length; j++) {
if (indicesByRow[i].length === 0 || indicesByRow[j].length === 0) {
continue;
}
if (!_.isEqual(indicesByRow[i], indicesByRow[j])) {
return false;
}
}
}
return true;
}
/**
*
* @param {string[][]} areas
* @returns {string[]}
*/
function namedAreas(areas) {
const names = new Set(_.flatten(areas));
names.delete('.');
return Array.from(names);
}
/**
*
* @param {string[][]} areas
* @returns {string[]}
*/
function findNotContiguousOrRectangular(areas) {
return namedAreas(areas).filter((name) => !isContiguousAndRectangular(areas, name));
}
module.exports = findNotContiguousOrRectangular;
@@ -0,0 +1,12 @@
'use strict';
/**
*
* @param {string[][]} areas
* @returns {boolean}
*/
function isRectangular(areas) {
return areas.every((row, i, arr) => row.length === arr[0].length);
}
module.exports = isRectangular;