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
+94
View File
@@ -0,0 +1,94 @@
# font-weight-notation
Require numeric or named (where possible) `font-weight` values. Also, when named values are expected, require only valid names.
<!-- prettier-ignore -->
```css
a { font-weight: bold }
/** ↑
* This notation */
a { font: italic small-caps 600 16px/3 cursive; }
/** ↑
* And this notation, too */
```
Valid font-weight names are `normal`, `bold`, `bolder`, and `lighter`.
This rule ignores `$sass`, `@less`, and `var(--custom-property)` variable syntaxes.
## Options
`string`: `"numeric"|"named-where-possible"`
### `"numeric"`
`font-weight` values _must always_ be numbers.
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a { font-weight: bold; }
```
<!-- prettier-ignore -->
```css
a { font: italic normal 20px sans-serif; }
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a { font-weight: 700; }
```
<!-- prettier-ignore -->
```css
a { font: italic 400 20px; }
```
### `"named-where-possible"`
`font-weight` values _must always_ be keywords when an appropriate keyword is available.
This means that only `400` and `700` will be rejected, because those are the only numbers with keyword equivalents (`normal` and `bold`).
The following patterns are considered violations:
<!-- prettier-ignore -->
```css
a { font-weight: 700; }
```
<!-- prettier-ignore -->
```css
a { font: italic 400 20px sans-serif; }
```
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a { font-weight: bold; }
```
<!-- prettier-ignore -->
```css
a { font: italic normal 20px sans-serif; }
```
## Optional secondary options
### `ignore: ["relative"]`
Ignore the [_relative_](https://drafts.csswg.org/css-fonts/#font-weight-prop) keyword names of `bolder` and `lighter`.
The following patterns are _not_ considered violations:
<!-- prettier-ignore -->
```css
a { font-weight: 400; }
a b { font-weight: lighter; }
```
+154
View File
@@ -0,0 +1,154 @@
// @ts-nocheck
'use strict';
const declarationValueIndex = require('../../utils/declarationValueIndex');
const isNumbery = require('../../utils/isNumbery');
const isStandardSyntaxValue = require('../../utils/isStandardSyntaxValue');
const isVariable = require('../../utils/isVariable');
const keywordSets = require('../../reference/keywordSets');
const optionsMatches = require('../../utils/optionsMatches');
const postcss = require('postcss');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');
const ruleName = 'font-weight-notation';
const messages = ruleMessages(ruleName, {
expected: (type) => `Expected ${type} font-weight notation`,
invalidNamed: (name) => `Unexpected invalid font-weight name "${name}"`,
});
const INHERIT_KEYWORD = 'inherit';
const INITIAL_KEYWORD = 'initial';
const NORMAL_KEYWORD = 'normal';
const WEIGHTS_WITH_KEYWORD_EQUIVALENTS = new Set(['400', '700']);
function rule(expectation, options) {
return (root, result) => {
const validOptions = validateOptions(
result,
ruleName,
{
actual: expectation,
possible: ['numeric', 'named-where-possible'],
},
{
actual: options,
possible: {
ignore: ['relative'],
},
optional: true,
},
);
if (!validOptions) {
return;
}
root.walkDecls((decl) => {
if (decl.prop.toLowerCase() === 'font-weight') {
checkWeight(decl.value, decl);
}
if (decl.prop.toLowerCase() === 'font') {
checkFont(decl);
}
});
function checkFont(decl) {
const valueList = postcss.list.space(decl.value);
// We do not need to more carefully distinguish font-weight
// numbers from unitless line-heights because line-heights in
// `font` values need to be part of a font-size/line-height pair
const hasNumericFontWeight = valueList.some(isNumbery);
for (const value of postcss.list.space(decl.value)) {
if (
(value.toLowerCase() === NORMAL_KEYWORD && !hasNumericFontWeight) ||
isNumbery(value) ||
(value.toLowerCase() !== NORMAL_KEYWORD &&
keywordSets.fontWeightKeywords.has(value.toLowerCase()))
) {
checkWeight(value, decl);
return;
}
}
}
function checkWeight(weightValue, decl) {
if (!isStandardSyntaxValue(weightValue)) {
return;
}
if (isVariable(weightValue)) {
return;
}
if (
weightValue.toLowerCase() === INHERIT_KEYWORD ||
weightValue.toLowerCase() === INITIAL_KEYWORD
) {
return;
}
if (
optionsMatches(options, 'ignore', 'relative') &&
keywordSets.fontWeightRelativeKeywords.has(weightValue.toLowerCase())
) {
return;
}
const weightValueOffset = decl.value.indexOf(weightValue);
if (expectation === 'numeric') {
if (decl.parent.type === 'atrule' && decl.parent.name.toLowerCase() === 'font-face') {
const weightValueNumbers = postcss.list.space(weightValue);
if (!weightValueNumbers.every(isNumbery)) {
return complain(messages.expected('numeric'));
}
return;
}
if (!isNumbery(weightValue)) {
return complain(messages.expected('numeric'));
}
}
if (expectation === 'named-where-possible') {
if (isNumbery(weightValue)) {
if (WEIGHTS_WITH_KEYWORD_EQUIVALENTS.has(weightValue)) {
complain(messages.expected('named'));
}
return;
}
if (
!keywordSets.fontWeightKeywords.has(weightValue.toLowerCase()) &&
weightValue.toLowerCase() !== NORMAL_KEYWORD
) {
return complain(messages.invalidNamed(weightValue));
}
}
function complain(message) {
report({
ruleName,
result,
message,
node: decl,
index: declarationValueIndex(decl) + weightValueOffset,
});
}
}
};
}
rule.ruleName = ruleName;
rule.messages = messages;
module.exports = rule;