@atlaskit/eslint-plugin-ui-styling-standard 0.8.0 → 0.8.2
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/CHANGELOG.md +14 -0
- package/dist/cjs/rules/convert-props-syntax/index.js +5 -0
- package/dist/cjs/rules/no-nested-selectors/index.js +2 -2
- package/dist/cjs/rules/utils/create-rule.js +4 -29
- package/dist/es2019/rules/convert-props-syntax/index.js +5 -0
- package/dist/es2019/rules/no-nested-selectors/index.js +3 -3
- package/dist/es2019/rules/utils/create-rule.js +2 -23
- package/dist/esm/rules/convert-props-syntax/index.js +5 -0
- package/dist/esm/rules/no-nested-selectors/index.js +3 -3
- package/dist/esm/rules/utils/create-rule.js +2 -25
- package/dist/types/rules/external-rules.d.ts +1 -1
- package/dist/types/rules/utils/create-rule.d.ts +1 -58
- package/dist/types-ts4.5/rules/external-rules.d.ts +1 -1
- package/dist/types-ts4.5/rules/utils/create-rule.d.ts +1 -58
- package/package.json +3 -3
- package/scripts/codegen.tsx +4 -1
- package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +52 -0
- package/src/rules/convert-props-syntax/index.tsx +10 -0
- package/src/rules/external-rules.tsx +2 -1
- package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +49 -0
- package/src/rules/no-nested-selectors/index.tsx +1 -4
- package/src/rules/utils/create-rule.tsx +5 -69
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 0.8.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#88753](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/88753) [`df5cbd4957ea`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/df5cbd4957ea) - Fixed no nested selectors rule to skip @ queries, cssMap and keyFrames calls
|
|
8
|
+
|
|
9
|
+
## 0.8.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#88029](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/88029) [`01d74d2899d5`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/01d74d2899d5) - Disabled ESlint rule convert-props-syntax on .attrs() calls
|
|
14
|
+
- [#87476](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/87476) [`af296d200ad2`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/af296d200ad2) - Internal refactoring to use `getCreateLintRule` from `@atlaskit/eslint-utils`
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
3
17
|
## 0.8.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
|
@@ -382,6 +382,11 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
382
382
|
return {
|
|
383
383
|
'CallExpression[callee.type="MemberExpression"]': function CallExpressionCalleeTypeMemberExpression(node) {
|
|
384
384
|
var references = context.getScope().references;
|
|
385
|
+
|
|
386
|
+
// Rule should ignore .attrs() calls
|
|
387
|
+
if (node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'attrs') {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
385
390
|
var callee = node.callee.type === 'MemberExpression' ? node.callee.object : node.callee;
|
|
386
391
|
if (!(0, _isSupportedImport.isStyledComponents)(callee, references) && !(0, _isSupportedImport.isEmotion)(callee, references)) {
|
|
387
392
|
return;
|
|
@@ -54,7 +54,7 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
54
54
|
references = _context$getScope.references;
|
|
55
55
|
var ancestors = context.getAncestors();
|
|
56
56
|
if (ancestors.every(function (ancestor) {
|
|
57
|
-
return ancestor.type !== 'CallExpression' || !(ancestor !== null && ancestor !== void 0 && ancestor.callee) || !((0, _isSupportedImport.isCss)(ancestor.callee, references, importSources) || (0, _isSupportedImport.isStyled)(ancestor.callee, references, importSources) || (0, _isSupportedImport.
|
|
57
|
+
return ancestor.type !== 'CallExpression' || !(ancestor !== null && ancestor !== void 0 && ancestor.callee) || !((0, _isSupportedImport.isCss)(ancestor.callee, references, importSources) || (0, _isSupportedImport.isStyled)(ancestor.callee, references, importSources) || (0, _isSupportedImport.isXcss)(ancestor.callee, references, importSources));
|
|
58
58
|
})) {
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
@@ -67,7 +67,7 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
var tokens = cssSelector.split(/[, ]+/);
|
|
70
|
-
if (!tokens.every(function (token) {
|
|
70
|
+
if (!cssSelector.includes('@') && !tokens.every(function (token) {
|
|
71
71
|
return token.length === 0 || token.startsWith('&') || token.startsWith(':') || token.includes('+') || token.includes('~') || token.endsWith('&');
|
|
72
72
|
})) {
|
|
73
73
|
context.report({
|
|
@@ -3,41 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.getPathSafeName = getPathSafeName;
|
|
6
|
+
exports.createLintRule = void 0;
|
|
8
7
|
exports.getRuleUrl = getRuleUrl;
|
|
9
|
-
var
|
|
10
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* We are moving to our own small abstraction to create a lint rule that we have the power
|
|
14
|
-
* to change and mold to our own needs.
|
|
15
|
-
*
|
|
16
|
-
* @see createLintRule
|
|
17
|
-
*
|
|
18
|
-
* @private
|
|
19
|
-
* @deprecated
|
|
20
|
-
*/
|
|
21
|
-
var createRule = exports.createRule = _utils.ESLintUtils.RuleCreator(function (name) {
|
|
22
|
-
return getRuleUrl(name);
|
|
23
|
-
});
|
|
8
|
+
var _createRule = require("@atlaskit/eslint-utils/create-rule");
|
|
24
9
|
/**
|
|
25
10
|
* Tiny wrapped over the ESLint rule module type that ensures
|
|
26
11
|
* there is a docs link to our ESLint plugin documentation page,
|
|
27
12
|
* as well as improving type support.
|
|
28
13
|
*/
|
|
29
|
-
var createLintRule = exports.createLintRule =
|
|
30
|
-
rule.meta.docs.url = getRuleUrl(rule.meta.name);
|
|
31
|
-
return rule;
|
|
32
|
-
};
|
|
14
|
+
var createLintRule = exports.createLintRule = (0, _createRule.getCreateLintRule)(getRuleUrl);
|
|
33
15
|
function getRuleUrl(ruleName) {
|
|
34
|
-
var name = getPathSafeName(ruleName);
|
|
16
|
+
var name = (0, _createRule.getPathSafeName)(ruleName);
|
|
35
17
|
return "https://atlassian.design/components/eslint-plugin-ui-styling-standard/".concat(name, "/usage");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* If it's a nested rule, ensure the url is clean and safe for urls, file paths, etc.
|
|
40
|
-
*/
|
|
41
|
-
function getPathSafeName(ruleName) {
|
|
42
|
-
return ruleName.replace('/', '-');
|
|
43
18
|
}
|
|
@@ -278,6 +278,11 @@ export const rule = createLintRule({
|
|
|
278
278
|
return {
|
|
279
279
|
'CallExpression[callee.type="MemberExpression"]': node => {
|
|
280
280
|
const references = context.getScope().references;
|
|
281
|
+
|
|
282
|
+
// Rule should ignore .attrs() calls
|
|
283
|
+
if (node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'attrs') {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
281
286
|
const callee = node.callee.type === 'MemberExpression' ? node.callee.object : node.callee;
|
|
282
287
|
if (!isStyledComponents(callee, references) && !isEmotion(callee, references)) {
|
|
283
288
|
return;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isStyled, isCss,
|
|
1
|
+
import { isStyled, isCss, isXcss, getImportSources } from '@atlaskit/eslint-utils/is-supported-import';
|
|
2
2
|
import { createLintRule } from '../utils/create-rule';
|
|
3
3
|
const schema = [{
|
|
4
4
|
type: 'object',
|
|
@@ -46,7 +46,7 @@ export const rule = createLintRule({
|
|
|
46
46
|
references
|
|
47
47
|
} = context.getScope();
|
|
48
48
|
const ancestors = context.getAncestors();
|
|
49
|
-
if (ancestors.every(ancestor => ancestor.type !== 'CallExpression' || !(ancestor !== null && ancestor !== void 0 && ancestor.callee) || !(isCss(ancestor.callee, references, importSources) || isStyled(ancestor.callee, references, importSources) ||
|
|
49
|
+
if (ancestors.every(ancestor => ancestor.type !== 'CallExpression' || !(ancestor !== null && ancestor !== void 0 && ancestor.callee) || !(isCss(ancestor.callee, references, importSources) || isStyled(ancestor.callee, references, importSources) || isXcss(ancestor.callee, references, importSources)))) {
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
if (node.value.type !== 'ObjectExpression') {
|
|
@@ -58,7 +58,7 @@ export const rule = createLintRule({
|
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
const tokens = cssSelector.split(/[, ]+/);
|
|
61
|
-
if (!tokens.every(token => token.length === 0 || token.startsWith('&') || token.startsWith(':') || token.includes('+') || token.includes('~') || token.endsWith('&'))) {
|
|
61
|
+
if (!cssSelector.includes('@') && !tokens.every(token => token.length === 0 || token.startsWith('&') || token.startsWith(':') || token.includes('+') || token.includes('~') || token.endsWith('&'))) {
|
|
62
62
|
context.report({
|
|
63
63
|
messageId: 'no-nested-selectors',
|
|
64
64
|
node: node.key
|
|
@@ -1,33 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
1
|
+
import { getCreateLintRule, getPathSafeName } from '@atlaskit/eslint-utils/create-rule';
|
|
3
2
|
|
|
4
|
-
/**
|
|
5
|
-
* We are moving to our own small abstraction to create a lint rule that we have the power
|
|
6
|
-
* to change and mold to our own needs.
|
|
7
|
-
*
|
|
8
|
-
* @see createLintRule
|
|
9
|
-
*
|
|
10
|
-
* @private
|
|
11
|
-
* @deprecated
|
|
12
|
-
*/
|
|
13
|
-
export const createRule = ESLintUtils.RuleCreator(name => getRuleUrl(name));
|
|
14
3
|
/**
|
|
15
4
|
* Tiny wrapped over the ESLint rule module type that ensures
|
|
16
5
|
* there is a docs link to our ESLint plugin documentation page,
|
|
17
6
|
* as well as improving type support.
|
|
18
7
|
*/
|
|
19
|
-
export const createLintRule =
|
|
20
|
-
rule.meta.docs.url = getRuleUrl(rule.meta.name);
|
|
21
|
-
return rule;
|
|
22
|
-
};
|
|
8
|
+
export const createLintRule = getCreateLintRule(getRuleUrl);
|
|
23
9
|
export function getRuleUrl(ruleName) {
|
|
24
10
|
const name = getPathSafeName(ruleName);
|
|
25
11
|
return `https://atlassian.design/components/eslint-plugin-ui-styling-standard/${name}/usage`;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* If it's a nested rule, ensure the url is clean and safe for urls, file paths, etc.
|
|
30
|
-
*/
|
|
31
|
-
export function getPathSafeName(ruleName) {
|
|
32
|
-
return ruleName.replace('/', '-');
|
|
33
12
|
}
|
|
@@ -376,6 +376,11 @@ export var rule = createLintRule({
|
|
|
376
376
|
return {
|
|
377
377
|
'CallExpression[callee.type="MemberExpression"]': function CallExpressionCalleeTypeMemberExpression(node) {
|
|
378
378
|
var references = context.getScope().references;
|
|
379
|
+
|
|
380
|
+
// Rule should ignore .attrs() calls
|
|
381
|
+
if (node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'attrs') {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
379
384
|
var callee = node.callee.type === 'MemberExpression' ? node.callee.object : node.callee;
|
|
380
385
|
if (!isStyledComponents(callee, references) && !isEmotion(callee, references)) {
|
|
381
386
|
return;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isStyled, isCss,
|
|
1
|
+
import { isStyled, isCss, isXcss, getImportSources } from '@atlaskit/eslint-utils/is-supported-import';
|
|
2
2
|
import { createLintRule } from '../utils/create-rule';
|
|
3
3
|
var schema = [{
|
|
4
4
|
type: 'object',
|
|
@@ -48,7 +48,7 @@ export var rule = createLintRule({
|
|
|
48
48
|
references = _context$getScope.references;
|
|
49
49
|
var ancestors = context.getAncestors();
|
|
50
50
|
if (ancestors.every(function (ancestor) {
|
|
51
|
-
return ancestor.type !== 'CallExpression' || !(ancestor !== null && ancestor !== void 0 && ancestor.callee) || !(isCss(ancestor.callee, references, importSources) || isStyled(ancestor.callee, references, importSources) ||
|
|
51
|
+
return ancestor.type !== 'CallExpression' || !(ancestor !== null && ancestor !== void 0 && ancestor.callee) || !(isCss(ancestor.callee, references, importSources) || isStyled(ancestor.callee, references, importSources) || isXcss(ancestor.callee, references, importSources));
|
|
52
52
|
})) {
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
@@ -61,7 +61,7 @@ export var rule = createLintRule({
|
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
var tokens = cssSelector.split(/[, ]+/);
|
|
64
|
-
if (!tokens.every(function (token) {
|
|
64
|
+
if (!cssSelector.includes('@') && !tokens.every(function (token) {
|
|
65
65
|
return token.length === 0 || token.startsWith('&') || token.startsWith(':') || token.includes('+') || token.includes('~') || token.endsWith('&');
|
|
66
66
|
})) {
|
|
67
67
|
context.report({
|
|
@@ -1,35 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
1
|
+
import { getCreateLintRule, getPathSafeName } from '@atlaskit/eslint-utils/create-rule';
|
|
3
2
|
|
|
4
|
-
/**
|
|
5
|
-
* We are moving to our own small abstraction to create a lint rule that we have the power
|
|
6
|
-
* to change and mold to our own needs.
|
|
7
|
-
*
|
|
8
|
-
* @see createLintRule
|
|
9
|
-
*
|
|
10
|
-
* @private
|
|
11
|
-
* @deprecated
|
|
12
|
-
*/
|
|
13
|
-
export var createRule = ESLintUtils.RuleCreator(function (name) {
|
|
14
|
-
return getRuleUrl(name);
|
|
15
|
-
});
|
|
16
3
|
/**
|
|
17
4
|
* Tiny wrapped over the ESLint rule module type that ensures
|
|
18
5
|
* there is a docs link to our ESLint plugin documentation page,
|
|
19
6
|
* as well as improving type support.
|
|
20
7
|
*/
|
|
21
|
-
export var createLintRule =
|
|
22
|
-
rule.meta.docs.url = getRuleUrl(rule.meta.name);
|
|
23
|
-
return rule;
|
|
24
|
-
};
|
|
8
|
+
export var createLintRule = getCreateLintRule(getRuleUrl);
|
|
25
9
|
export function getRuleUrl(ruleName) {
|
|
26
10
|
var name = getPathSafeName(ruleName);
|
|
27
11
|
return "https://atlassian.design/components/eslint-plugin-ui-styling-standard/".concat(name, "/usage");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* If it's a nested rule, ensure the url is clean and safe for urls, file paths, etc.
|
|
32
|
-
*/
|
|
33
|
-
export function getPathSafeName(ruleName) {
|
|
34
|
-
return ruleName.replace('/', '-');
|
|
35
12
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { LintRuleMeta } from '@atlaskit/eslint-utils/create-rule';
|
|
2
2
|
/** External rules must be scoped, have a display name, and external urls. */
|
|
3
3
|
export type ExternalRuleMeta = LintRuleMeta & {
|
|
4
4
|
isExternal: true;
|
|
@@ -1,64 +1,7 @@
|
|
|
1
|
-
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
-
import type { Rule } from 'eslint';
|
|
3
|
-
/**
|
|
4
|
-
* We are moving to our own small abstraction to create a lint rule that we have the power
|
|
5
|
-
* to change and mold to our own needs.
|
|
6
|
-
*
|
|
7
|
-
* @see createLintRule
|
|
8
|
-
*
|
|
9
|
-
* @private
|
|
10
|
-
* @deprecated
|
|
11
|
-
*/
|
|
12
|
-
export declare const createRule: <TOptions extends readonly unknown[], TMessageIds extends string, TRuleListener extends import("@typescript-eslint/utils/dist/ts-eslint").RuleListener = import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>({ name, meta, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<TOptions, TMessageIds, TRuleListener>>) => import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<TMessageIds, TOptions, TRuleListener>;
|
|
13
|
-
export interface LintRule extends Omit<Rule.RuleModule, 'meta'> {
|
|
14
|
-
/**
|
|
15
|
-
* Including this for backwards compat moving from the typescript-eslint util.
|
|
16
|
-
*/
|
|
17
|
-
name?: never;
|
|
18
|
-
meta: LintRuleMeta;
|
|
19
|
-
}
|
|
20
|
-
export interface LintRuleMeta extends Omit<Rule.RuleMetaData, 'docs'> {
|
|
21
|
-
/**
|
|
22
|
-
* Name of the rule.
|
|
23
|
-
* Must match the folder it is in exactly else build will throw.
|
|
24
|
-
* Add an exception in codegen.tsx for nested rules.
|
|
25
|
-
*/
|
|
26
|
-
name: string;
|
|
27
|
-
docs: {
|
|
28
|
-
/**
|
|
29
|
-
* Short description of what this rule does.
|
|
30
|
-
*/
|
|
31
|
-
description: string;
|
|
32
|
-
/**
|
|
33
|
-
* Specifies the URL at which the full documentation can be accessed.
|
|
34
|
-
*/
|
|
35
|
-
url?: string | undefined;
|
|
36
|
-
/**
|
|
37
|
-
* If this rule should be in the recommended preset or not.
|
|
38
|
-
* Set to `false` to exclude it from the recommended preset.
|
|
39
|
-
*/
|
|
40
|
-
recommended: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* The severity level to be applied to this rule.
|
|
43
|
-
* When setting to `"error"` it will mean releasing a breaking change.
|
|
44
|
-
*/
|
|
45
|
-
severity: 'error' | 'warn';
|
|
46
|
-
/**
|
|
47
|
-
* This is configuration passed into the plugin to configure the rule.
|
|
48
|
-
*
|
|
49
|
-
* Eg. `{ excludeReactComponents: true }` would be passed into the plugin config
|
|
50
|
-
*/
|
|
51
|
-
pluginConfig?: Record<string, any>;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
1
|
/**
|
|
55
2
|
* Tiny wrapped over the ESLint rule module type that ensures
|
|
56
3
|
* there is a docs link to our ESLint plugin documentation page,
|
|
57
4
|
* as well as improving type support.
|
|
58
5
|
*/
|
|
59
|
-
export declare const createLintRule: (rule: LintRule) => Rule.RuleModule;
|
|
6
|
+
export declare const createLintRule: (rule: import("@atlaskit/eslint-utils/create-rule").LintRule) => import("eslint").Rule.RuleModule;
|
|
60
7
|
export declare function getRuleUrl(ruleName: string): string;
|
|
61
|
-
/**
|
|
62
|
-
* If it's a nested rule, ensure the url is clean and safe for urls, file paths, etc.
|
|
63
|
-
*/
|
|
64
|
-
export declare function getPathSafeName(ruleName: string): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { LintRuleMeta } from '@atlaskit/eslint-utils/create-rule';
|
|
2
2
|
/** External rules must be scoped, have a display name, and external urls. */
|
|
3
3
|
export type ExternalRuleMeta = LintRuleMeta & {
|
|
4
4
|
isExternal: true;
|
|
@@ -1,64 +1,7 @@
|
|
|
1
|
-
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
-
import type { Rule } from 'eslint';
|
|
3
|
-
/**
|
|
4
|
-
* We are moving to our own small abstraction to create a lint rule that we have the power
|
|
5
|
-
* to change and mold to our own needs.
|
|
6
|
-
*
|
|
7
|
-
* @see createLintRule
|
|
8
|
-
*
|
|
9
|
-
* @private
|
|
10
|
-
* @deprecated
|
|
11
|
-
*/
|
|
12
|
-
export declare const createRule: <TOptions extends readonly unknown[], TMessageIds extends string, TRuleListener extends import("@typescript-eslint/utils/dist/ts-eslint").RuleListener = import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>({ name, meta, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<TOptions, TMessageIds, TRuleListener>>) => import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<TMessageIds, TOptions, TRuleListener>;
|
|
13
|
-
export interface LintRule extends Omit<Rule.RuleModule, 'meta'> {
|
|
14
|
-
/**
|
|
15
|
-
* Including this for backwards compat moving from the typescript-eslint util.
|
|
16
|
-
*/
|
|
17
|
-
name?: never;
|
|
18
|
-
meta: LintRuleMeta;
|
|
19
|
-
}
|
|
20
|
-
export interface LintRuleMeta extends Omit<Rule.RuleMetaData, 'docs'> {
|
|
21
|
-
/**
|
|
22
|
-
* Name of the rule.
|
|
23
|
-
* Must match the folder it is in exactly else build will throw.
|
|
24
|
-
* Add an exception in codegen.tsx for nested rules.
|
|
25
|
-
*/
|
|
26
|
-
name: string;
|
|
27
|
-
docs: {
|
|
28
|
-
/**
|
|
29
|
-
* Short description of what this rule does.
|
|
30
|
-
*/
|
|
31
|
-
description: string;
|
|
32
|
-
/**
|
|
33
|
-
* Specifies the URL at which the full documentation can be accessed.
|
|
34
|
-
*/
|
|
35
|
-
url?: string | undefined;
|
|
36
|
-
/**
|
|
37
|
-
* If this rule should be in the recommended preset or not.
|
|
38
|
-
* Set to `false` to exclude it from the recommended preset.
|
|
39
|
-
*/
|
|
40
|
-
recommended: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* The severity level to be applied to this rule.
|
|
43
|
-
* When setting to `"error"` it will mean releasing a breaking change.
|
|
44
|
-
*/
|
|
45
|
-
severity: 'error' | 'warn';
|
|
46
|
-
/**
|
|
47
|
-
* This is configuration passed into the plugin to configure the rule.
|
|
48
|
-
*
|
|
49
|
-
* Eg. `{ excludeReactComponents: true }` would be passed into the plugin config
|
|
50
|
-
*/
|
|
51
|
-
pluginConfig?: Record<string, any>;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
1
|
/**
|
|
55
2
|
* Tiny wrapped over the ESLint rule module type that ensures
|
|
56
3
|
* there is a docs link to our ESLint plugin documentation page,
|
|
57
4
|
* as well as improving type support.
|
|
58
5
|
*/
|
|
59
|
-
export declare const createLintRule: (rule: LintRule) => Rule.RuleModule;
|
|
6
|
+
export declare const createLintRule: (rule: import("@atlaskit/eslint-utils/create-rule").LintRule) => import("eslint").Rule.RuleModule;
|
|
60
7
|
export declare function getRuleUrl(ruleName: string): string;
|
|
61
|
-
/**
|
|
62
|
-
* If it's a nested rule, ensure the url is clean and safe for urls, file paths, etc.
|
|
63
|
-
*/
|
|
64
|
-
export declare function getPathSafeName(ruleName: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-ui-styling-standard",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"author": "Atlassian Pty Ltd",
|
|
5
5
|
"description": "The eslint plugin to enforce and educate on Atlassian's UI Styling Standard",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
".": "./src/index.tsx"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@atlaskit/eslint-utils": "^1.
|
|
39
|
+
"@atlaskit/eslint-utils": "^1.1.0",
|
|
40
40
|
"@babel/runtime": "^7.0.0",
|
|
41
41
|
"@typescript-eslint/utils": "^5.48.1",
|
|
42
42
|
"eslint-codemod-utils": "^1.8.6",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@atlaskit/ds-lib": "^2.2.0",
|
|
48
|
-
"@atlaskit/eslint-plugin-design-system": "^9.
|
|
48
|
+
"@atlaskit/eslint-plugin-design-system": "^9.3.0",
|
|
49
49
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
50
50
|
"@atlassian/codegen": "*",
|
|
51
51
|
"@compiled/eslint-plugin": "^0.13.6",
|
package/scripts/codegen.tsx
CHANGED
|
@@ -8,7 +8,10 @@ import { format, resolveConfig } from 'prettier';
|
|
|
8
8
|
|
|
9
9
|
import { createSignedArtifact } from '@atlassian/codegen';
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
type LintRule,
|
|
13
|
+
getPathSafeName,
|
|
14
|
+
} from '@atlaskit/eslint-utils/create-rule';
|
|
12
15
|
import {
|
|
13
16
|
externalRules,
|
|
14
17
|
type ExternalRuleMeta,
|
|
@@ -103,6 +103,58 @@ typescriptEslintTester.run(
|
|
|
103
103
|
});
|
|
104
104
|
`,
|
|
105
105
|
},
|
|
106
|
+
{
|
|
107
|
+
name: 'ignores styled(...).attrs() call',
|
|
108
|
+
code: `
|
|
109
|
+
import { styled } from 'styled-components';
|
|
110
|
+
|
|
111
|
+
const StyledMinimized = styled(Minimized).attrs({
|
|
112
|
+
className: (props) => props.transitionClass,
|
|
113
|
+
})\`
|
|
114
|
+
color: blue;
|
|
115
|
+
\`;
|
|
116
|
+
`,
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: 'ignores styled.div.attrs<...>() call',
|
|
120
|
+
code: `
|
|
121
|
+
import { styled } from '@compiled/react';
|
|
122
|
+
|
|
123
|
+
export const ModalAnchorOld = styled.div.attrs<ModalAnchorProps>({
|
|
124
|
+
style: ({ left, top }: ModalAnchorProps) => ({
|
|
125
|
+
left,
|
|
126
|
+
top,
|
|
127
|
+
}),
|
|
128
|
+
})\`
|
|
129
|
+
position: fixed;
|
|
130
|
+
\`;
|
|
131
|
+
`,
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: 'ignores styled.div.attrs() call',
|
|
135
|
+
code: `
|
|
136
|
+
const BlanketControl = styled.div.attrs({
|
|
137
|
+
style: ({ scrollOffset, width }) => ({
|
|
138
|
+
top: scrollOffset,
|
|
139
|
+
bottom: -scrollOffset,
|
|
140
|
+
width,
|
|
141
|
+
}),
|
|
142
|
+
})\`
|
|
143
|
+
display: flex;
|
|
144
|
+
justify-content: center;
|
|
145
|
+
\`;
|
|
146
|
+
`,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: 'ignores styled.img.attrs() call',
|
|
150
|
+
code: `
|
|
151
|
+
export const FieldsRestoredIllustration = styled.img.attrs({ src: fieldsRestoredImage })\`
|
|
152
|
+
display: block;
|
|
153
|
+
min-height: 190px;
|
|
154
|
+
max-width: 290px;
|
|
155
|
+
\`;
|
|
156
|
+
`,
|
|
157
|
+
},
|
|
106
158
|
],
|
|
107
159
|
invalid: [
|
|
108
160
|
{
|
|
@@ -394,6 +394,16 @@ export const rule = createLintRule({
|
|
|
394
394
|
node: CallExpression,
|
|
395
395
|
) => {
|
|
396
396
|
const references = context.getScope().references;
|
|
397
|
+
|
|
398
|
+
// Rule should ignore .attrs() calls
|
|
399
|
+
if (
|
|
400
|
+
node.callee.type === 'MemberExpression' &&
|
|
401
|
+
node.callee.property.type === 'Identifier' &&
|
|
402
|
+
node.callee.property.name === 'attrs'
|
|
403
|
+
) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
|
|
397
407
|
const callee =
|
|
398
408
|
node.callee.type === 'MemberExpression'
|
|
399
409
|
? node.callee.object
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { LintRuleMeta } from '@atlaskit/eslint-utils/create-rule';
|
|
2
|
+
import { getRuleUrl } from './utils/create-rule';
|
|
2
3
|
|
|
3
4
|
/** External rules must be scoped, have a display name, and external urls. */
|
|
4
5
|
export type ExternalRuleMeta = LintRuleMeta & {
|
|
@@ -94,6 +94,55 @@ typescriptEslintTester.run(
|
|
|
94
94
|
});
|
|
95
95
|
`,
|
|
96
96
|
},
|
|
97
|
+
{
|
|
98
|
+
name: 'Skips @ queries',
|
|
99
|
+
code: `
|
|
100
|
+
import { css } from '@compiled/react';
|
|
101
|
+
const styles = css({
|
|
102
|
+
'@container (width > 400px)': {
|
|
103
|
+
fontSize: '1.5rem',
|
|
104
|
+
},
|
|
105
|
+
'@media (max-width: 1200px)': {
|
|
106
|
+
gridTemplateColumns: 'repeat(1, 1fr)',
|
|
107
|
+
justifyItems: 'center',
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
`,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: 'Skip cssMap call',
|
|
114
|
+
code: `
|
|
115
|
+
import { cssMap } from '@atlaskit/css';
|
|
116
|
+
|
|
117
|
+
const styles = cssMap({
|
|
118
|
+
success: {
|
|
119
|
+
color: 'var(--ds-text-inverse)',
|
|
120
|
+
backgroundColor: 'var(--ds-background-success-bold)',
|
|
121
|
+
'&:hover': {
|
|
122
|
+
backgroundColor: 'var(--ds-background-success-bold-hovered)',
|
|
123
|
+
},
|
|
124
|
+
'&:active': {
|
|
125
|
+
backgroundColor: 'var(--ds-background-success-bold-pressed)',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
`,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
name: 'Skip keyframes call',
|
|
133
|
+
code: `
|
|
134
|
+
import { keyframes } from '@emotion/react';
|
|
135
|
+
|
|
136
|
+
const keyFrameStyles = keyframes({
|
|
137
|
+
'from, to': {
|
|
138
|
+
opacity: 0,
|
|
139
|
+
},
|
|
140
|
+
'50%': {
|
|
141
|
+
opacity: 1,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
`,
|
|
145
|
+
},
|
|
97
146
|
],
|
|
98
147
|
invalid: [
|
|
99
148
|
{
|
|
@@ -3,8 +3,6 @@ import type { Property } from 'estree';
|
|
|
3
3
|
import {
|
|
4
4
|
isStyled,
|
|
5
5
|
isCss,
|
|
6
|
-
isKeyframes,
|
|
7
|
-
isCssMap,
|
|
8
6
|
isXcss,
|
|
9
7
|
getImportSources,
|
|
10
8
|
} from '@atlaskit/eslint-utils/is-supported-import';
|
|
@@ -70,8 +68,6 @@ export const rule = createLintRule({
|
|
|
70
68
|
!(
|
|
71
69
|
isCss(ancestor.callee, references, importSources) ||
|
|
72
70
|
isStyled(ancestor.callee, references, importSources) ||
|
|
73
|
-
isKeyframes(ancestor.callee, references, importSources) ||
|
|
74
|
-
isCssMap(ancestor.callee, references, importSources) ||
|
|
75
71
|
isXcss(ancestor.callee, references, importSources)
|
|
76
72
|
),
|
|
77
73
|
)
|
|
@@ -92,6 +88,7 @@ export const rule = createLintRule({
|
|
|
92
88
|
const tokens = cssSelector.split(/[, ]+/);
|
|
93
89
|
|
|
94
90
|
if (
|
|
91
|
+
!cssSelector.includes('@') &&
|
|
95
92
|
!tokens.every(
|
|
96
93
|
(token) =>
|
|
97
94
|
token.length === 0 ||
|
|
@@ -1,80 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* We are moving to our own small abstraction to create a lint rule that we have the power
|
|
7
|
-
* to change and mold to our own needs.
|
|
8
|
-
*
|
|
9
|
-
* @see createLintRule
|
|
10
|
-
*
|
|
11
|
-
* @private
|
|
12
|
-
* @deprecated
|
|
13
|
-
*/
|
|
14
|
-
export const createRule = ESLintUtils.RuleCreator((name) => getRuleUrl(name));
|
|
15
|
-
|
|
16
|
-
export interface LintRule extends Omit<Rule.RuleModule, 'meta'> {
|
|
17
|
-
/**
|
|
18
|
-
* Including this for backwards compat moving from the typescript-eslint util.
|
|
19
|
-
*/
|
|
20
|
-
name?: never;
|
|
21
|
-
meta: LintRuleMeta;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface LintRuleMeta extends Omit<Rule.RuleMetaData, 'docs'> {
|
|
25
|
-
/**
|
|
26
|
-
* Name of the rule.
|
|
27
|
-
* Must match the folder it is in exactly else build will throw.
|
|
28
|
-
* Add an exception in codegen.tsx for nested rules.
|
|
29
|
-
*/
|
|
30
|
-
name: string;
|
|
31
|
-
docs: {
|
|
32
|
-
/**
|
|
33
|
-
* Short description of what this rule does.
|
|
34
|
-
*/
|
|
35
|
-
description: string;
|
|
36
|
-
/**
|
|
37
|
-
* Specifies the URL at which the full documentation can be accessed.
|
|
38
|
-
*/
|
|
39
|
-
url?: string | undefined;
|
|
40
|
-
/**
|
|
41
|
-
* If this rule should be in the recommended preset or not.
|
|
42
|
-
* Set to `false` to exclude it from the recommended preset.
|
|
43
|
-
*/
|
|
44
|
-
recommended: boolean;
|
|
45
|
-
/**
|
|
46
|
-
* The severity level to be applied to this rule.
|
|
47
|
-
* When setting to `"error"` it will mean releasing a breaking change.
|
|
48
|
-
*/
|
|
49
|
-
severity: 'error' | 'warn';
|
|
50
|
-
/**
|
|
51
|
-
* This is configuration passed into the plugin to configure the rule.
|
|
52
|
-
*
|
|
53
|
-
* Eg. `{ excludeReactComponents: true }` would be passed into the plugin config
|
|
54
|
-
*/
|
|
55
|
-
pluginConfig?: Record<string, any>;
|
|
56
|
-
};
|
|
57
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
getCreateLintRule,
|
|
3
|
+
getPathSafeName,
|
|
4
|
+
} from '@atlaskit/eslint-utils/create-rule';
|
|
58
5
|
|
|
59
6
|
/**
|
|
60
7
|
* Tiny wrapped over the ESLint rule module type that ensures
|
|
61
8
|
* there is a docs link to our ESLint plugin documentation page,
|
|
62
9
|
* as well as improving type support.
|
|
63
10
|
*/
|
|
64
|
-
export const createLintRule = (
|
|
65
|
-
(rule.meta.docs as Record<string, unknown>).url = getRuleUrl(rule.meta.name);
|
|
66
|
-
|
|
67
|
-
return rule as Rule.RuleModule;
|
|
68
|
-
};
|
|
11
|
+
export const createLintRule = getCreateLintRule(getRuleUrl);
|
|
69
12
|
|
|
70
13
|
export function getRuleUrl(ruleName: string) {
|
|
71
14
|
const name = getPathSafeName(ruleName);
|
|
72
15
|
return `https://atlassian.design/components/eslint-plugin-ui-styling-standard/${name}/usage`;
|
|
73
16
|
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* If it's a nested rule, ensure the url is clean and safe for urls, file paths, etc.
|
|
77
|
-
*/
|
|
78
|
-
export function getPathSafeName(ruleName: string) {
|
|
79
|
-
return ruleName.replace('/', '-');
|
|
80
|
-
}
|