@dialpad/stylelint-plugin-dialtone 1.0.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +3 -1
- package/lib/rules/recommend-font-style-tokens.js +53 -0
- package/lib/rules/use-dialtone-tokens.js +69 -0
- package/package.json +10 -2
- package/.eslintrc.js +0 -17
- package/.markdownlint.json +0 -3
- package/CHANGELOG.json +0 -1
- package/CHANGELOG.md +0 -20
- package/docs/rules/no-mixins.md +0 -35
- package/project.json +0 -26
- package/release-ci.config.cjs +0 -32
- package/release-local.config.cjs +0 -40
- package/tests/lib/rules/no-mixins.mjs +0 -51
package/lib/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const noMixins = require("./rules/no-mixins");
|
|
4
|
+
const recommendFontStyleTokens = require("./rules/recommend-font-style-tokens");
|
|
5
|
+
const useDialtoneTokens = require("./rules/use-dialtone-tokens");
|
|
4
6
|
|
|
5
|
-
module.exports = [noMixins];
|
|
7
|
+
module.exports = [noMixins, recommendFontStyleTokens, useDialtoneTokens];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const stylelint = require("stylelint");
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
createPlugin,
|
|
5
|
+
utils: { report, ruleMessages, validateOptions },
|
|
6
|
+
} = stylelint;
|
|
7
|
+
|
|
8
|
+
const ruleName = '@dialpad/stylelint-plugin-dialtone/recommend-font-style-tokens';
|
|
9
|
+
|
|
10
|
+
const messages = ruleMessages(ruleName, {
|
|
11
|
+
recommendFontStyleTokens: (property) => `Instead of setting "${property}" it is
|
|
12
|
+
preferred to set the property Font to a composition token that bundles font-family, font-weight, font-size, and line-height.
|
|
13
|
+
More information can be found here:
|
|
14
|
+
https://dialtone.dialpad.com/design/typography/#api. There can be cases where using these selectors is intentional and valid,
|
|
15
|
+
in which case you can ignore this warning.`,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const meta = {
|
|
19
|
+
url: "https://github.com/dialpad/dialtone/blob/staging/packages/stylelint-plugin-dialtone/docs/rules/recommend-font-style-tokens.md",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** @type {import('stylelint').Rule} */
|
|
23
|
+
const ruleFunction = (primary) => {
|
|
24
|
+
// reject setting font-size, font-family, font-weight, and line-height separately
|
|
25
|
+
return (root, result) => {
|
|
26
|
+
const validOptions = validateOptions(result, ruleName, {
|
|
27
|
+
actual: primary,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (!validOptions) return;
|
|
31
|
+
|
|
32
|
+
// This iterates through one selector at a time, so you don't have to worry about checking for nested selectors.
|
|
33
|
+
root.walkDecls((declNode) => {
|
|
34
|
+
const typographyProperties = ['font-family', 'font-weight', 'font-size', 'line-height'];
|
|
35
|
+
if (typographyProperties.includes(declNode.prop)) {
|
|
36
|
+
report({
|
|
37
|
+
result,
|
|
38
|
+
ruleName,
|
|
39
|
+
node: declNode,
|
|
40
|
+
start: declNode.source.start,
|
|
41
|
+
end: declNode.source.end,
|
|
42
|
+
message: messages.recommendFontStyleTokens(declNode.prop),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
ruleFunction.ruleName = ruleName;
|
|
50
|
+
ruleFunction.messages = messages;
|
|
51
|
+
ruleFunction.meta = meta;
|
|
52
|
+
|
|
53
|
+
module.exports = createPlugin(ruleName, ruleFunction);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const stylelint = require("stylelint");
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
createPlugin,
|
|
5
|
+
utils: { report, ruleMessages, validateOptions },
|
|
6
|
+
} = stylelint;
|
|
7
|
+
|
|
8
|
+
const ruleName = '@dialpad/stylelint-plugin-dialtone/use-dialtone-tokens';
|
|
9
|
+
|
|
10
|
+
const messages = ruleMessages(ruleName, {
|
|
11
|
+
useDialtoneTokens: (value) => `Use a Dialtone token instead of "${value}".
|
|
12
|
+
A list of available tokens can be found here: https://dialtone.dialpad.com/tokens.
|
|
13
|
+
Consult with design on which token should be used and only with their approval ignore this rule.`,
|
|
14
|
+
useRemInsteadOfPx: (value) => `If it's not possible to use a Dialtone token, use ${pxToRem(value)} instead of ${value}.`,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const pxToRem = (value) => {
|
|
18
|
+
const val = parseFloat(value.replace('px', ''));
|
|
19
|
+
return val / 10 + 'rem';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const meta = {
|
|
23
|
+
url: "https://github.com/dialpad/dialtone/blob/staging/packages/stylelint-plugin-dialtone/docs/rules/use-dialtone-tokens.md",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** @type {import('stylelint').Rule} */
|
|
27
|
+
const ruleFunction = (primary) => {
|
|
28
|
+
// detects the use of px or rem in properties and suggests to use a Dialtone token
|
|
29
|
+
// or rem instead of px if a Dialtone token is not available
|
|
30
|
+
return (root, result) => {
|
|
31
|
+
const validOptions = validateOptions(result, ruleName, {
|
|
32
|
+
actual: primary,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (!validOptions) return;
|
|
36
|
+
|
|
37
|
+
// This iterates through one selector at a time, so you don't have to worry about checking for nested selectors.
|
|
38
|
+
root.walkDecls((declNode) => {
|
|
39
|
+
const hasRemUnit = declNode.value.includes('rem');
|
|
40
|
+
const hasPxUnit = declNode.value.includes('px');
|
|
41
|
+
if (hasRemUnit || hasPxUnit) {
|
|
42
|
+
report({
|
|
43
|
+
result,
|
|
44
|
+
ruleName,
|
|
45
|
+
node: declNode,
|
|
46
|
+
start: declNode.source.start,
|
|
47
|
+
end: declNode.source.end,
|
|
48
|
+
message: messages.useDialtoneTokens(declNode.value),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (hasPxUnit) {
|
|
52
|
+
report({
|
|
53
|
+
result,
|
|
54
|
+
ruleName,
|
|
55
|
+
node: declNode,
|
|
56
|
+
start: declNode.source.start,
|
|
57
|
+
end: declNode.source.end,
|
|
58
|
+
message: messages.useRemInsteadOfPx(declNode.value),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
ruleFunction.ruleName = ruleName;
|
|
66
|
+
ruleFunction.messages = messages;
|
|
67
|
+
ruleFunction.meta = meta;
|
|
68
|
+
|
|
69
|
+
module.exports = createPlugin(ruleName, ruleFunction);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dialpad/stylelint-plugin-dialtone",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "dialtone stylelint plugin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Dialpad",
|
|
@@ -39,9 +39,11 @@
|
|
|
39
39
|
},
|
|
40
40
|
"license": "MIT",
|
|
41
41
|
"main": "./lib/index.js",
|
|
42
|
+
"files": [
|
|
43
|
+
"lib"
|
|
44
|
+
],
|
|
42
45
|
"exports": "./lib/index.js",
|
|
43
46
|
"devDependencies": {
|
|
44
|
-
"stylelint": "15.11.0",
|
|
45
47
|
"stylelint-test-rule-node": "^0.2.1"
|
|
46
48
|
},
|
|
47
49
|
"engines": {
|
|
@@ -50,6 +52,12 @@
|
|
|
50
52
|
"peerDependencies": {
|
|
51
53
|
"stylelint": "^14.0.0 || ^15.0.0"
|
|
52
54
|
},
|
|
55
|
+
"nx": {
|
|
56
|
+
"includedScripts": [
|
|
57
|
+
"lint",
|
|
58
|
+
"test"
|
|
59
|
+
]
|
|
60
|
+
},
|
|
53
61
|
"scripts": {
|
|
54
62
|
"lint": "run-s lint:docs lint:code",
|
|
55
63
|
"lint:code": "eslint '**/*.js'",
|
package/.eslintrc.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
root: true,
|
|
5
|
-
extends: [
|
|
6
|
-
"eslint:recommended",
|
|
7
|
-
"plugin:eslint-plugin/recommended",
|
|
8
|
-
"plugin:node/recommended",
|
|
9
|
-
],
|
|
10
|
-
parserOptions: {
|
|
11
|
-
ecmaVersion: 'latest',
|
|
12
|
-
parser: "vue-eslint-parser"
|
|
13
|
-
},
|
|
14
|
-
env: {
|
|
15
|
-
node: true,
|
|
16
|
-
},
|
|
17
|
-
};
|
package/.markdownlint.json
DELETED
package/CHANGELOG.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"versions":[{"version":"1.0.2","title":"[1.0.2](https://github.com/dialpad/dialtone/compare/stylelint-plugin-dialtone/v1.0.1...stylelint-plugin-dialtone/v1.0.2) (2024-03-26)","date":"2024-03-26","body":"### Bug Fixes\n\n* NO-JIRA release not working with new commit convention ([#235](https://github.com/dialpad/dialtone/issues/235)) ([28ff27c](https://github.com/dialpad/dialtone/commit/28ff27cffac5e751eaf8496b7c716710a0153a61))","parsed":{"_":["NO-JIRA release not working with new commit convention (#235) (28ff27c)"],"Bug Fixes":["NO-JIRA release not working with new commit convention (#235) (28ff27c)"]}},{"version":"1.0.1","title":"[1.0.1](https://github.com/dialpad/dialtone/compare/stylelint-plugin-dialtone/v1.0.0...stylelint-plugin-dialtone/v1.0.1) (2024-03-20)","date":"2024-03-20","body":"### Bug Fixes\n\n* use mixin property to detect mixin ([#215](https://github.com/dialpad/dialtone/issues/215)) ([493f58e](https://github.com/dialpad/dialtone/commit/493f58ef37ea14392bfee0fabc7c0cf8fa524d2a))\n\n\n\n### Features\n\n* dialtone stylelint plugin - no mixins rule ([#186](https://github.com/dialpad/dialtone/issues/186)) ([8fe0ffb](https://github.com/dialpad/dialtone/commit/8fe0ffb7f4dd81cbf19e6cbbe37b16ca609973cd))","parsed":{"_":["use mixin property to detect mixin (#215) (493f58e)","dialtone stylelint plugin - no mixins rule (#186) (8fe0ffb)"],"Bug Fixes":["use mixin property to detect mixin (#215) (493f58e)"],"Features":["dialtone stylelint plugin - no mixins rule (#186) (8fe0ffb)"]}}],"title":"1.0.0 (2024-03-07)"}
|
package/CHANGELOG.md
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
## [1.0.2](https://github.com/dialpad/dialtone/compare/stylelint-plugin-dialtone/v1.0.1...stylelint-plugin-dialtone/v1.0.2) (2024-03-26)
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
### Bug Fixes
|
|
5
|
-
|
|
6
|
-
* NO-JIRA release not working with new commit convention ([#235](https://github.com/dialpad/dialtone/issues/235)) ([28ff27c](https://github.com/dialpad/dialtone/commit/28ff27cffac5e751eaf8496b7c716710a0153a61))
|
|
7
|
-
|
|
8
|
-
## [1.0.1](https://github.com/dialpad/dialtone/compare/stylelint-plugin-dialtone/v1.0.0...stylelint-plugin-dialtone/v1.0.1) (2024-03-20)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
### Bug Fixes
|
|
12
|
-
|
|
13
|
-
* use mixin property to detect mixin ([#215](https://github.com/dialpad/dialtone/issues/215)) ([493f58e](https://github.com/dialpad/dialtone/commit/493f58ef37ea14392bfee0fabc7c0cf8fa524d2a))
|
|
14
|
-
|
|
15
|
-
# 1.0.0 (2024-03-07)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
### Features
|
|
19
|
-
|
|
20
|
-
* dialtone stylelint plugin - no mixins rule ([#186](https://github.com/dialpad/dialtone/issues/186)) ([8fe0ffb](https://github.com/dialpad/dialtone/commit/8fe0ffb7f4dd81cbf19e6cbbe37b16ca609973cd))
|
package/docs/rules/no-mixins.md
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# Detects usage of LESS mixins (no-mixins)
|
|
2
|
-
|
|
3
|
-
LESS mixin usage is one of the primary causes of our extremely slow front end build performance. We are attempting to remove as many LESS mixins as possible and eventually transition to a more modern pure CSS approach.
|
|
4
|
-
|
|
5
|
-
## Rule Details
|
|
6
|
-
|
|
7
|
-
This rule aims to detect and prevent usage of LESS mixins.
|
|
8
|
-
|
|
9
|
-
Examples of **incorrect** code for this rule:
|
|
10
|
-
|
|
11
|
-
Mixin usage:
|
|
12
|
-
|
|
13
|
-
```css
|
|
14
|
-
.a {
|
|
15
|
-
.aMixin();
|
|
16
|
-
}
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
Older style mixin syntax usage:
|
|
20
|
-
|
|
21
|
-
```css
|
|
22
|
-
.a {
|
|
23
|
-
.aMixin;
|
|
24
|
-
}
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
Examples of **correct** code for this rule:
|
|
28
|
-
|
|
29
|
-
No mixins used.
|
|
30
|
-
|
|
31
|
-
```css
|
|
32
|
-
.a {
|
|
33
|
-
color: var(--dt-color-foreground-critical);
|
|
34
|
-
}
|
|
35
|
-
```
|
package/project.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "stylelint-plugin-dialtone",
|
|
3
|
-
"targets": {
|
|
4
|
-
"publish": {
|
|
5
|
-
"executor": "nx:run-commands",
|
|
6
|
-
"options": {
|
|
7
|
-
"command": "pnpm publish --filter ./packages/stylelint-plugin-dialtone",
|
|
8
|
-
"parallel": false
|
|
9
|
-
}
|
|
10
|
-
},
|
|
11
|
-
"release-github": {
|
|
12
|
-
"executor": "nx:run-commands",
|
|
13
|
-
"options": {
|
|
14
|
-
"command": "pnpm semantic-release-plus --extends ./packages/stylelint-plugin-dialtone/release-ci.config.cjs",
|
|
15
|
-
"parallel": false
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
"release-local": {
|
|
19
|
-
"executor": "nx:run-commands",
|
|
20
|
-
"options": {
|
|
21
|
-
"command": "pnpm semantic-release-plus --no-ci --extends ./packages/stylelint-plugin-dialtone/release-local.config.cjs",
|
|
22
|
-
"parallel": false
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
package/release-ci.config.cjs
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const name = 'stylelint-plugin-dialtone';
|
|
2
|
-
const srcRoot = `packages/${name}`;
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
extends: 'release.config.base.js',
|
|
6
|
-
pkgRoot: srcRoot,
|
|
7
|
-
tagFormat: name + '/v${version}',
|
|
8
|
-
commitPaths: [`${srcRoot}/*`],
|
|
9
|
-
plugins: [
|
|
10
|
-
['@semantic-release/commit-analyzer', {
|
|
11
|
-
preset: 'angular',
|
|
12
|
-
releaseRules: [
|
|
13
|
-
{ type: 'refactor', release: 'patch' },
|
|
14
|
-
],
|
|
15
|
-
}],
|
|
16
|
-
['@semantic-release/release-notes-generator', {
|
|
17
|
-
config: '@dialpad/conventional-changelog-angular',
|
|
18
|
-
}],
|
|
19
|
-
'@semantic-release/github',
|
|
20
|
-
],
|
|
21
|
-
branches: [
|
|
22
|
-
'production',
|
|
23
|
-
{
|
|
24
|
-
name: 'beta',
|
|
25
|
-
prerelease: true,
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
name: 'alpha',
|
|
29
|
-
prerelease: true,
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
};
|
package/release-local.config.cjs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const name = 'stylelint-plugin-dialtone';
|
|
2
|
-
const srcRoot = `packages/${name}`;
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
extends: 'release.config.base.js',
|
|
6
|
-
pkgRoot: srcRoot,
|
|
7
|
-
tagFormat: name + '/v${version}',
|
|
8
|
-
commitPaths: [`${srcRoot}/*`],
|
|
9
|
-
assets: [`${srcRoot}/CHANGELOG.md`, `${srcRoot}/CHANGELOG.json`, `${srcRoot}/package.json`],
|
|
10
|
-
plugins: [
|
|
11
|
-
['@semantic-release/commit-analyzer', {
|
|
12
|
-
preset: 'angular',
|
|
13
|
-
releaseRules: [
|
|
14
|
-
{ type: 'refactor', release: 'patch' },
|
|
15
|
-
],
|
|
16
|
-
}],
|
|
17
|
-
['@semantic-release/release-notes-generator', {
|
|
18
|
-
config: '@dialpad/conventional-changelog-angular',
|
|
19
|
-
}],
|
|
20
|
-
['@dialpad/semantic-release-changelog-json', { changelogFile: `${srcRoot}/CHANGELOG.md`, changelogJsonFile: `${srcRoot}/CHANGELOG.json` }],
|
|
21
|
-
['@semantic-release/changelog', { changelogFile: `${srcRoot}/CHANGELOG.md` }],
|
|
22
|
-
['@semantic-release/npm', { npmPublish: false }],
|
|
23
|
-
['@semantic-release/git', {
|
|
24
|
-
/* eslint-disable-next-line no-template-curly-in-string */
|
|
25
|
-
message: `chore(release): NO-JIRA ${name}` +
|
|
26
|
-
'/v${nextRelease.version}\n\n${nextRelease.notes}',
|
|
27
|
-
}],
|
|
28
|
-
],
|
|
29
|
-
branches: [
|
|
30
|
-
'staging',
|
|
31
|
-
{
|
|
32
|
-
name: 'beta',
|
|
33
|
-
prerelease: true,
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
name: 'alpha',
|
|
37
|
-
prerelease: true,
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { testRule } from 'stylelint-test-rule-node';
|
|
2
|
-
|
|
3
|
-
import plugin from '../../../lib/rules/no-mixins.js';
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
rule: { messages, ruleName },
|
|
7
|
-
} = plugin;
|
|
8
|
-
|
|
9
|
-
testRule({
|
|
10
|
-
plugins: [plugin],
|
|
11
|
-
ruleName,
|
|
12
|
-
config: true,
|
|
13
|
-
customSyntax: 'postcss-less',
|
|
14
|
-
|
|
15
|
-
accept: [
|
|
16
|
-
{
|
|
17
|
-
code: '.a { color: red; }',
|
|
18
|
-
description: 'simple class definition with no LESS mixin',
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
|
|
22
|
-
reject: [
|
|
23
|
-
{
|
|
24
|
-
code: `.a {
|
|
25
|
-
.aMixin();
|
|
26
|
-
}`,
|
|
27
|
-
description: 'simple class definition containing a LESS mixin',
|
|
28
|
-
message: messages.noMixinsRejected('aMixin'),
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
code: `.a {
|
|
32
|
-
.aMixin;
|
|
33
|
-
}`,
|
|
34
|
-
description: 'simple class definition containing the older syntax for LESS mixins',
|
|
35
|
-
message: messages.noMixinsRejected('aMixin'),
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
code: `.a {
|
|
39
|
-
color: red;
|
|
40
|
-
.aMixin;
|
|
41
|
-
vertical-align: middle;
|
|
42
|
-
.otherMixin();
|
|
43
|
-
}`,
|
|
44
|
-
description: 'multiple mixins in a class definition',
|
|
45
|
-
warnings: [
|
|
46
|
-
{ message: messages.noMixinsRejected('aMixin') },
|
|
47
|
-
{ message: messages.noMixinsRejected('otherMixin') },
|
|
48
|
-
],
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
});
|