@atlaskit/eslint-plugin-ui-styling-standard 1.6.3 → 1.6.4
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 +8 -0
- package/dist/cjs/rules/atlaskit-theme/index.js +2 -2
- package/dist/cjs/rules/convert-props-syntax/index.js +2 -2
- package/dist/cjs/rules/enforce-style-prop/index.js +2 -2
- package/dist/cjs/rules/external-rules.js +7 -7
- package/dist/cjs/rules/local-cx-xcss/index.js +2 -2
- package/dist/cjs/rules/no-array-arguments/index.js +2 -2
- package/dist/cjs/rules/no-classname-prop/index.js +2 -2
- package/dist/cjs/rules/no-container-queries/index.js +2 -2
- package/dist/cjs/rules/no-dynamic-styles/index.js +2 -2
- package/dist/cjs/rules/no-exported-styles/index.js +2 -2
- package/dist/cjs/rules/no-global-styles/index.js +2 -2
- package/dist/cjs/rules/no-important-styles/index.js +2 -2
- package/dist/cjs/rules/no-imported-style-values/index.js +2 -2
- package/dist/cjs/rules/no-nested-selectors/index.js +2 -2
- package/dist/cjs/rules/no-styled/index.js +2 -2
- package/dist/cjs/rules/no-unsafe-selectors/constants.js +2 -55
- package/dist/cjs/rules/no-unsafe-selectors/get-source-location-from-range.js +19 -0
- package/dist/cjs/rules/no-unsafe-selectors/index.js +6 -2
- package/dist/cjs/rules/no-unsafe-selectors/lint-selector.js +8 -6
- package/dist/cjs/rules/no-unsafe-selectors/source-position-utils.js +0 -14
- package/dist/cjs/rules/no-unsafe-selectors/walk-css-map.js +47 -2
- package/dist/cjs/rules/no-unsafe-values/index.js +2 -2
- package/dist/cjs/rules/no-unsafe-values/utils.js +10 -4
- package/dist/cjs/rules/no-unused-cssmap-properties/index.js +2 -2
- package/dist/cjs/rules/use-compiled/index.js +18 -10
- package/dist/cjs/rules/use-compiled/is-import-default-specifier.js +9 -0
- package/dist/cjs/rules/use-compiled/is-import-namespace-specifier.js +9 -0
- package/dist/cjs/rules/use-compiled/is-import-specifier.js +9 -0
- package/dist/cjs/rules/use-compiled/is-safe-css.js +20 -0
- package/dist/cjs/rules/use-compiled/is-safe-keyframes.js +36 -0
- package/dist/cjs/rules/use-compiled/is-safe-property.js +24 -0
- package/dist/cjs/rules/use-compiled/is-safe-style-argument.js +16 -0
- package/dist/cjs/rules/use-compiled/is-safe-style-object.js +18 -0
- package/dist/cjs/rules/use-compiled/is-safe-styled.js +25 -0
- package/dist/cjs/rules/use-compiled/is-safe-usage.js +37 -0
- package/dist/cjs/rules/use-compiled/utils.js +21 -12
- package/dist/cjs/rules/utils/create-rule-with-typed-config.js +2 -2
- package/dist/cjs/rules/utils/create-rule.js +8 -6
- package/dist/cjs/rules/utils/get-rule-url.js +11 -0
- package/dist/es2019/rules/atlaskit-theme/index.js +1 -1
- package/dist/es2019/rules/convert-props-syntax/index.js +1 -1
- package/dist/es2019/rules/enforce-style-prop/index.js +1 -1
- package/dist/es2019/rules/external-rules.js +1 -1
- package/dist/es2019/rules/local-cx-xcss/index.js +1 -1
- package/dist/es2019/rules/no-array-arguments/index.js +1 -1
- package/dist/es2019/rules/no-classname-prop/index.js +1 -1
- package/dist/es2019/rules/no-container-queries/index.js +1 -1
- package/dist/es2019/rules/no-dynamic-styles/index.js +1 -1
- package/dist/es2019/rules/no-exported-styles/index.js +1 -1
- package/dist/es2019/rules/no-global-styles/index.js +1 -1
- package/dist/es2019/rules/no-important-styles/index.js +1 -1
- package/dist/es2019/rules/no-imported-style-values/index.js +1 -1
- package/dist/es2019/rules/no-nested-selectors/index.js +1 -1
- package/dist/es2019/rules/no-styled/index.js +1 -1
- package/dist/es2019/rules/no-unsafe-selectors/constants.js +1 -54
- package/dist/es2019/rules/no-unsafe-selectors/get-source-location-from-range.js +8 -0
- package/dist/es2019/rules/no-unsafe-selectors/index.js +5 -1
- package/dist/es2019/rules/no-unsafe-selectors/lint-selector.js +4 -2
- package/dist/es2019/rules/no-unsafe-selectors/source-position-utils.js +0 -8
- package/dist/es2019/rules/no-unsafe-selectors/walk-css-map.js +47 -1
- package/dist/es2019/rules/no-unsafe-values/index.js +1 -1
- package/dist/es2019/rules/no-unsafe-values/utils.js +9 -3
- package/dist/es2019/rules/no-unused-cssmap-properties/index.js +1 -1
- package/dist/es2019/rules/use-compiled/index.js +14 -5
- package/dist/es2019/rules/use-compiled/is-import-default-specifier.js +3 -0
- package/dist/es2019/rules/use-compiled/is-import-namespace-specifier.js +3 -0
- package/dist/es2019/rules/use-compiled/is-import-specifier.js +3 -0
- package/dist/es2019/rules/use-compiled/is-safe-css.js +14 -0
- package/dist/es2019/rules/use-compiled/is-safe-keyframes.js +28 -0
- package/dist/es2019/rules/use-compiled/is-safe-property.js +18 -0
- package/dist/es2019/rules/use-compiled/is-safe-style-argument.js +11 -0
- package/dist/es2019/rules/use-compiled/is-safe-style-object.js +10 -0
- package/dist/es2019/rules/use-compiled/is-safe-styled.js +19 -0
- package/dist/es2019/rules/use-compiled/is-safe-usage.js +32 -0
- package/dist/es2019/rules/use-compiled/utils.js +3 -9
- package/dist/es2019/rules/utils/create-rule-with-typed-config.js +1 -1
- package/dist/es2019/rules/utils/create-rule.js +3 -6
- package/dist/es2019/rules/utils/get-rule-url.js +5 -0
- package/dist/esm/rules/atlaskit-theme/index.js +1 -1
- package/dist/esm/rules/convert-props-syntax/index.js +1 -1
- package/dist/esm/rules/enforce-style-prop/index.js +1 -1
- package/dist/esm/rules/external-rules.js +1 -1
- package/dist/esm/rules/local-cx-xcss/index.js +1 -1
- package/dist/esm/rules/no-array-arguments/index.js +1 -1
- package/dist/esm/rules/no-classname-prop/index.js +1 -1
- package/dist/esm/rules/no-container-queries/index.js +1 -1
- package/dist/esm/rules/no-dynamic-styles/index.js +1 -1
- package/dist/esm/rules/no-exported-styles/index.js +1 -1
- package/dist/esm/rules/no-global-styles/index.js +1 -1
- package/dist/esm/rules/no-important-styles/index.js +1 -1
- package/dist/esm/rules/no-imported-style-values/index.js +1 -1
- package/dist/esm/rules/no-nested-selectors/index.js +1 -1
- package/dist/esm/rules/no-styled/index.js +1 -1
- package/dist/esm/rules/no-unsafe-selectors/constants.js +1 -54
- package/dist/esm/rules/no-unsafe-selectors/get-source-location-from-range.js +12 -0
- package/dist/esm/rules/no-unsafe-selectors/index.js +5 -1
- package/dist/esm/rules/no-unsafe-selectors/lint-selector.js +4 -2
- package/dist/esm/rules/no-unsafe-selectors/source-position-utils.js +0 -12
- package/dist/esm/rules/no-unsafe-selectors/walk-css-map.js +47 -1
- package/dist/esm/rules/no-unsafe-values/index.js +1 -1
- package/dist/esm/rules/no-unsafe-values/utils.js +10 -4
- package/dist/esm/rules/no-unused-cssmap-properties/index.js +1 -1
- package/dist/esm/rules/use-compiled/index.js +13 -5
- package/dist/esm/rules/use-compiled/is-import-default-specifier.js +3 -0
- package/dist/esm/rules/use-compiled/is-import-namespace-specifier.js +3 -0
- package/dist/esm/rules/use-compiled/is-import-specifier.js +3 -0
- package/dist/esm/rules/use-compiled/is-safe-css.js +14 -0
- package/dist/esm/rules/use-compiled/is-safe-keyframes.js +30 -0
- package/dist/esm/rules/use-compiled/is-safe-property.js +18 -0
- package/dist/esm/rules/use-compiled/is-safe-style-argument.js +11 -0
- package/dist/esm/rules/use-compiled/is-safe-style-object.js +12 -0
- package/dist/esm/rules/use-compiled/is-safe-styled.js +19 -0
- package/dist/esm/rules/use-compiled/is-safe-usage.js +31 -0
- package/dist/esm/rules/use-compiled/utils.js +3 -9
- package/dist/esm/rules/utils/create-rule-with-typed-config.js +1 -1
- package/dist/esm/rules/utils/create-rule.js +3 -6
- package/dist/esm/rules/utils/get-rule-url.js +5 -0
- package/dist/types/rules/atlaskit-theme/index.d.ts +1 -1
- package/dist/types/rules/convert-props-syntax/index.d.ts +1 -1
- package/dist/types/rules/enforce-style-prop/index.d.ts +1 -1
- package/dist/types/rules/local-cx-xcss/index.d.ts +1 -1
- package/dist/types/rules/no-array-arguments/index.d.ts +1 -1
- package/dist/types/rules/no-classname-prop/index.d.ts +1 -1
- package/dist/types/rules/no-container-queries/index.d.ts +1 -1
- package/dist/types/rules/no-dynamic-styles/index.d.ts +1 -1
- package/dist/types/rules/no-exported-styles/index.d.ts +1 -1
- package/dist/types/rules/no-global-styles/index.d.ts +1 -1
- package/dist/types/rules/no-important-styles/index.d.ts +1 -1
- package/dist/types/rules/no-imported-style-values/index.d.ts +1 -1
- package/dist/types/rules/no-nested-selectors/index.d.ts +1 -1
- package/dist/types/rules/no-styled/index.d.ts +1 -1
- package/dist/types/rules/no-unsafe-selectors/constants.d.ts +0 -47
- package/dist/types/rules/no-unsafe-selectors/get-source-location-from-range.d.ts +4 -0
- package/dist/types/rules/no-unsafe-selectors/source-position-utils.d.ts +0 -2
- package/dist/types/rules/no-unsafe-values/index.d.ts +1 -1
- package/dist/types/rules/no-unused-cssmap-properties/index.d.ts +1 -1
- package/dist/types/rules/use-compiled/index.d.ts +1 -1
- package/dist/types/rules/use-compiled/is-import-default-specifier.d.ts +2 -0
- package/dist/types/rules/use-compiled/is-import-namespace-specifier.d.ts +2 -0
- package/dist/types/rules/use-compiled/is-import-specifier.d.ts +2 -0
- package/dist/types/rules/use-compiled/is-safe-css.d.ts +2 -0
- package/dist/types/rules/use-compiled/is-safe-keyframes.d.ts +2 -0
- package/dist/types/rules/use-compiled/is-safe-property.d.ts +2 -0
- package/dist/types/rules/use-compiled/is-safe-style-argument.d.ts +5 -0
- package/dist/types/rules/use-compiled/is-safe-style-object.d.ts +2 -0
- package/dist/types/rules/use-compiled/is-safe-styled.d.ts +2 -0
- package/dist/types/rules/use-compiled/is-safe-usage.d.ts +7 -0
- package/dist/types/rules/use-compiled/utils.d.ts +3 -3
- package/dist/types/rules/utils/create-rule.d.ts +1 -1
- package/dist/types/rules/utils/get-rule-url.d.ts +1 -0
- package/dist/types-ts4.5/rules/atlaskit-theme/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/convert-props-syntax/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/enforce-style-prop/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/local-cx-xcss/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/no-array-arguments/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/no-classname-prop/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/no-container-queries/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/no-dynamic-styles/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/no-exported-styles/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/no-global-styles/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/no-important-styles/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/no-imported-style-values/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/no-nested-selectors/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/no-styled/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/no-unsafe-selectors/constants.d.ts +0 -47
- package/dist/types-ts4.5/rules/no-unsafe-selectors/get-source-location-from-range.d.ts +7 -0
- package/dist/types-ts4.5/rules/no-unsafe-selectors/source-position-utils.d.ts +0 -2
- package/dist/types-ts4.5/rules/no-unsafe-values/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/no-unused-cssmap-properties/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-compiled/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-compiled/is-import-default-specifier.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-compiled/is-import-namespace-specifier.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-compiled/is-import-specifier.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-compiled/is-safe-css.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-compiled/is-safe-keyframes.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-compiled/is-safe-property.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-compiled/is-safe-style-argument.d.ts +5 -0
- package/dist/types-ts4.5/rules/use-compiled/is-safe-style-object.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-compiled/is-safe-styled.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-compiled/is-safe-usage.d.ts +7 -0
- package/dist/types-ts4.5/rules/use-compiled/utils.d.ts +3 -3
- package/dist/types-ts4.5/rules/utils/create-rule.d.ts +1 -1
- package/dist/types-ts4.5/rules/utils/get-rule-url.d.ts +1 -0
- package/package.json +3 -3
- package/dist/cjs/rules/use-compiled/is-safe.js +0 -134
- package/dist/es2019/rules/use-compiled/is-safe.js +0 -122
- package/dist/esm/rules/use-compiled/is-safe.js +0 -125
- package/dist/types/rules/use-compiled/is-safe.d.ts +0 -10
- package/dist/types-ts4.5/rules/use-compiled/is-safe.d.ts +0 -10
|
@@ -15,57 +15,4 @@ export const allowedPseudos = new Set(
|
|
|
15
15
|
* The `&` is included above for type checking reasons,
|
|
16
16
|
* but we don't actually want it when consuming the values.
|
|
17
17
|
*/
|
|
18
|
-
cssPseudos.map(pseudo => pseudo.slice(1)));
|
|
19
|
-
export const legacyPseudoElements = new Set([':after', ':before', ':first-letter', ':first-line']);
|
|
20
|
-
export const ignoredAtRules = new Set(['@container',
|
|
21
|
-
// ignored because it's covered by `no-container-queries`
|
|
22
|
-
'@media',
|
|
23
|
-
// ignored because it's covered by `no-nested-styles`
|
|
24
|
-
'@supports', '@property', '@starting-style']);
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* At-rules that are allowed to be used in "grouped" form within cssMap.
|
|
28
|
-
*
|
|
29
|
-
* "Grouped" refers to the legacy Compiled syntax where an at-rule key with no parameters
|
|
30
|
-
* (matching `/^@[A-z-]+$/`) contains nested variant keys, like:
|
|
31
|
-
*
|
|
32
|
-
* ```typescript
|
|
33
|
-
* // ❌ GROUPED (not allowed for @media):
|
|
34
|
-
* cssMap({
|
|
35
|
-
* variant: {
|
|
36
|
-
* '@media': { // at-rule key with no parameters
|
|
37
|
-
* '(min-width: 900px)': {}, // nested variants
|
|
38
|
-
* '(min-width: 1200px)': {},
|
|
39
|
-
* }
|
|
40
|
-
* }
|
|
41
|
-
* })
|
|
42
|
-
*
|
|
43
|
-
* // ✅ FLAT (preferred for @media):
|
|
44
|
-
* cssMap({
|
|
45
|
-
* variant: {
|
|
46
|
-
* '@media (min-width: 900px)': {}, // at-rule with parameters
|
|
47
|
-
* '@media (min-width: 1200px)': {},
|
|
48
|
-
* }
|
|
49
|
-
* })
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* However, some at-rules like `@starting-style` have no parameters and can only be
|
|
53
|
-
* written in the "grouped" form at the variant level:
|
|
54
|
-
*
|
|
55
|
-
* ```typescript
|
|
56
|
-
* // ✅ ALLOWED (only valid syntax for @starting-style):
|
|
57
|
-
* cssMap({
|
|
58
|
-
* fade: {
|
|
59
|
-
* '@starting-style': { // at-rule with no parameters
|
|
60
|
-
* opacity: 0, // styles to apply
|
|
61
|
-
* }
|
|
62
|
-
* }
|
|
63
|
-
* })
|
|
64
|
-
* ```
|
|
65
|
-
*
|
|
66
|
-
* Note: This only applies to at-rules at the variant level. Nested at-rules inside
|
|
67
|
-
* other rulesets (e.g., `@starting-style` inside `@media (...)`) are handled by
|
|
68
|
-
* `walkStyleRuleset` and are not considered "grouped".
|
|
69
|
-
*/
|
|
70
|
-
export const allowedGroupedAtRules = new Set(['@starting-style' // Has no parameters, can only be written in grouped form
|
|
71
|
-
]);
|
|
18
|
+
cssPseudos.map(pseudo => pseudo.slice(1)));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
2
|
+
export function getSourceLocationFromRange(context, [start, end]) {
|
|
3
|
+
const sourceCode = getSourceCode(context);
|
|
4
|
+
return {
|
|
5
|
+
start: sourceCode.getLocFromIndex(start),
|
|
6
|
+
end: sourceCode.getLocFromIndex(end)
|
|
7
|
+
};
|
|
8
|
+
}
|
|
@@ -4,9 +4,13 @@ import { isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
|
4
4
|
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
5
5
|
import { walkStyleProperties } from '@atlaskit/eslint-utils/walk-style-properties';
|
|
6
6
|
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
7
|
-
import { ignoredAtRules } from './constants';
|
|
8
7
|
import { lintSelector } from './lint-selector';
|
|
9
8
|
import { walkCssMap } from './walk-css-map';
|
|
9
|
+
const ignoredAtRules = new Set(['@container',
|
|
10
|
+
// ignored because it's covered by `no-container-queries`
|
|
11
|
+
'@media',
|
|
12
|
+
// ignored because it's covered by `no-nested-styles`
|
|
13
|
+
'@supports', '@property', '@starting-style']);
|
|
10
14
|
const cssSelectorProcessor = cssSelectorParser();
|
|
11
15
|
const rule = createLintRuleWithTypedConfig({
|
|
12
16
|
meta: {
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { isNesting } from 'postcss-selector-parser';
|
|
2
|
-
import { allowedPseudos
|
|
3
|
-
import {
|
|
2
|
+
import { allowedPseudos } from './constants';
|
|
3
|
+
import { getSourceLocationFromRange } from './get-source-location-from-range';
|
|
4
|
+
import { getRangeFromNode } from './source-position-utils';
|
|
4
5
|
export function lintSelector(args) {
|
|
5
6
|
checkNoAmbiguousPseudos(args);
|
|
6
7
|
checkNoRestrictedPseudos(args);
|
|
7
8
|
checkNoLegacyPseudoElementSyntax(args);
|
|
8
9
|
checkNoIncreasedSpecificity(args);
|
|
9
10
|
}
|
|
11
|
+
const legacyPseudoElements = new Set([':after', ':before', ':first-letter', ':first-line']);
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Ensures the use of a nesting selector `&` with pseudo-selectors.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
2
1
|
export function getRangeFromNode({
|
|
3
2
|
node,
|
|
4
3
|
sourceNode
|
|
@@ -22,11 +21,4 @@ export function getRangeFromNode({
|
|
|
22
21
|
const start = adjustment + node.sourceIndex;
|
|
23
22
|
const end = start + node.value.length;
|
|
24
23
|
return [start, end];
|
|
25
|
-
}
|
|
26
|
-
export function getSourceLocationFromRange(context, [start, end]) {
|
|
27
|
-
const sourceCode = getSourceCode(context);
|
|
28
|
-
return {
|
|
29
|
-
start: sourceCode.getLocFromIndex(start),
|
|
30
|
-
end: sourceCode.getLocFromIndex(end)
|
|
31
|
-
};
|
|
32
24
|
}
|
|
@@ -5,7 +5,53 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* At-rules that are allowed to be used in "grouped" form within cssMap.
|
|
11
|
+
*
|
|
12
|
+
* "Grouped" refers to the legacy Compiled syntax where an at-rule key with no parameters
|
|
13
|
+
* (matching `/^@[A-z-]+$/`) contains nested variant keys, like:
|
|
14
|
+
*
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // ❌ GROUPED (not allowed for @media):
|
|
17
|
+
* cssMap({
|
|
18
|
+
* variant: {
|
|
19
|
+
* '@media': { // at-rule key with no parameters
|
|
20
|
+
* '(min-width: 900px)': {}, // nested variants
|
|
21
|
+
* '(min-width: 1200px)': {},
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* })
|
|
25
|
+
*
|
|
26
|
+
* // ✅ FLAT (preferred for @media):
|
|
27
|
+
* cssMap({
|
|
28
|
+
* variant: {
|
|
29
|
+
* '@media (min-width: 900px)': {}, // at-rule with parameters
|
|
30
|
+
* '@media (min-width: 1200px)': {},
|
|
31
|
+
* }
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* However, some at-rules like `@starting-style` have no parameters and can only be
|
|
36
|
+
* written in the "grouped" form at the variant level:
|
|
37
|
+
*
|
|
38
|
+
* ```typescript
|
|
39
|
+
* // ✅ ALLOWED (only valid syntax for @starting-style):
|
|
40
|
+
* cssMap({
|
|
41
|
+
* fade: {
|
|
42
|
+
* '@starting-style': { // at-rule with no parameters
|
|
43
|
+
* opacity: 0, // styles to apply
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
* })
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* Note: This only applies to at-rules at the variant level. Nested at-rules inside
|
|
50
|
+
* other rulesets (e.g., `@starting-style` inside `@media (...)`) are handled by
|
|
51
|
+
* `walkStyleRuleset` and are not considered "grouped".
|
|
52
|
+
*/
|
|
53
|
+
const allowedGroupedAtRules = new Set(['@starting-style' // Has no parameters, can only be written in grouped form
|
|
54
|
+
]);
|
|
9
55
|
export function walkCssMap({
|
|
10
56
|
context,
|
|
11
57
|
importSources,
|
|
@@ -39,6 +39,7 @@ export class Linter {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
lintIdentifier(value) {
|
|
42
|
+
var _this$context$sourceC;
|
|
42
43
|
if (value.name === 'undefined') {
|
|
43
44
|
/**
|
|
44
45
|
* `undefined` gets caught implicitly anyway by other checks below,
|
|
@@ -51,7 +52,8 @@ export class Linter {
|
|
|
51
52
|
}
|
|
52
53
|
const variable = findVariable({
|
|
53
54
|
identifier: value,
|
|
54
|
-
sourceCode
|
|
55
|
+
// @ts-ignore - Jira's ESLint v10 types expose sourceCode, platform still checks with ESLint v9.
|
|
56
|
+
sourceCode: (_this$context$sourceC = this.context.sourceCode) !== null && _this$context$sourceC !== void 0 ? _this$context$sourceC : this.context.getSourceCode()
|
|
55
57
|
});
|
|
56
58
|
if (!variable) {
|
|
57
59
|
this.lintUnhandledIdentifier(value);
|
|
@@ -135,13 +137,15 @@ export class Linter {
|
|
|
135
137
|
});
|
|
136
138
|
}
|
|
137
139
|
isAllowedDynamicKey(expression) {
|
|
140
|
+
var _this$context$sourceC2;
|
|
138
141
|
const identifier = findIdentifierNode(expression);
|
|
139
142
|
if (!identifier) {
|
|
140
143
|
return false;
|
|
141
144
|
}
|
|
142
145
|
const variable = findVariable({
|
|
143
146
|
identifier,
|
|
144
|
-
sourceCode
|
|
147
|
+
// @ts-ignore - Jira's ESLint v10 types expose sourceCode, platform still checks with ESLint v9.
|
|
148
|
+
sourceCode: (_this$context$sourceC2 = this.context.sourceCode) !== null && _this$context$sourceC2 !== void 0 ? _this$context$sourceC2 : this.context.getSourceCode()
|
|
145
149
|
});
|
|
146
150
|
if (!variable) {
|
|
147
151
|
return false;
|
|
@@ -174,13 +178,15 @@ export class Linter {
|
|
|
174
178
|
});
|
|
175
179
|
}
|
|
176
180
|
isAllowedFunctionCall(value) {
|
|
181
|
+
var _this$context$sourceC3;
|
|
177
182
|
const identifier = findIdentifierNode(value);
|
|
178
183
|
if (!identifier) {
|
|
179
184
|
return false;
|
|
180
185
|
}
|
|
181
186
|
const variable = findVariable({
|
|
182
187
|
identifier,
|
|
183
|
-
sourceCode
|
|
188
|
+
// @ts-ignore - Jira's ESLint v10 types expose sourceCode, platform still checks with ESLint v9.
|
|
189
|
+
sourceCode: (_this$context$sourceC3 = this.context.sourceCode) !== null && _this$context$sourceC3 !== void 0 ? _this$context$sourceC3 : this.context.getSourceCode()
|
|
184
190
|
});
|
|
185
191
|
if (!variable) {
|
|
186
192
|
return false;
|
|
@@ -2,8 +2,12 @@ import { identifier, importDeclaration, importSpecifier, literal } from 'eslint-
|
|
|
2
2
|
import { getAllComments } from '@atlaskit/eslint-utils/context-compat';
|
|
3
3
|
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
4
4
|
import { createLintRule } from '../utils/create-rule';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { isImportDefaultSpecifier } from './is-import-default-specifier';
|
|
6
|
+
import { isImportNamespaceSpecifier } from './is-import-namespace-specifier';
|
|
7
|
+
import { isImportSpecifier } from './is-import-specifier';
|
|
8
|
+
import { isSafeStyled } from './is-safe-styled';
|
|
9
|
+
import { isSafeUsage } from './is-safe-usage';
|
|
10
|
+
import { getFirstImportFromSource } from './utils';
|
|
7
11
|
const SUPPORTED_EMOTION_IMPORTS = new Set(['css', 'keyframes', 'ClassNames', 'jsx']);
|
|
8
12
|
const SUPPORTED_IMPORT_MAP = {
|
|
9
13
|
'@emotion/core': SUPPORTED_EMOTION_IMPORTS,
|
|
@@ -33,7 +37,7 @@ function readConfig(context) {
|
|
|
33
37
|
const [config] = context.options;
|
|
34
38
|
return Object.assign({}, defaultConfig, config);
|
|
35
39
|
}
|
|
36
|
-
|
|
40
|
+
const rule = createLintRule({
|
|
37
41
|
meta: {
|
|
38
42
|
name: 'use-compiled',
|
|
39
43
|
type: 'problem',
|
|
@@ -63,10 +67,13 @@ export const rule = createLintRule({
|
|
|
63
67
|
},
|
|
64
68
|
loc: pragma.loc,
|
|
65
69
|
*fix(fixer) {
|
|
70
|
+
var _context$sourceCode;
|
|
66
71
|
if (!config.canAutoFix) {
|
|
67
72
|
return;
|
|
68
73
|
}
|
|
69
|
-
|
|
74
|
+
|
|
75
|
+
// @ts-ignore - Jira's ESLint v10 types expose sourceCode, platform still checks with ESLint v9.
|
|
76
|
+
const importDeclarations = ((_context$sourceCode = context.sourceCode) !== null && _context$sourceCode !== void 0 ? _context$sourceCode : context.getSourceCode()).ast.body.filter(node => node.type === 'ImportDeclaration');
|
|
70
77
|
const hasEmotionImport = importDeclarations.some(importDeclaration => {
|
|
71
78
|
const importSource = importDeclaration.source.value;
|
|
72
79
|
return importSource.startsWith('@emotion/');
|
|
@@ -133,12 +140,14 @@ function getSpecifiers({
|
|
|
133
140
|
}
|
|
134
141
|
const defaultSpecifier = node.specifiers.find(isImportDefaultSpecifier);
|
|
135
142
|
if (defaultSpecifier) {
|
|
143
|
+
var _context$sourceCode2;
|
|
136
144
|
if (!supportedImports.has('default')) {
|
|
137
145
|
return;
|
|
138
146
|
}
|
|
139
147
|
const styled = findVariable({
|
|
140
148
|
identifier: defaultSpecifier.local,
|
|
141
|
-
sourceCode
|
|
149
|
+
// @ts-ignore - Jira's ESLint v10 types expose sourceCode, platform still checks with ESLint v9.
|
|
150
|
+
sourceCode: (_context$sourceCode2 = context.sourceCode) !== null && _context$sourceCode2 !== void 0 ? _context$sourceCode2 : context.getSourceCode()
|
|
142
151
|
});
|
|
143
152
|
if (!styled || !isSafeStyled(styled)) {
|
|
144
153
|
return;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { closestOfType } from 'eslint-codemod-utils';
|
|
2
|
+
import { isSafeStyleArgument } from './is-safe-style-argument';
|
|
3
|
+
export function isSafeCss(css) {
|
|
4
|
+
return css.references.every(ref => {
|
|
5
|
+
const callExpression = closestOfType(ref.identifier, 'CallExpression');
|
|
6
|
+
if (!callExpression) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if (callExpression.callee !== ref.identifier) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return callExpression.arguments.every(isSafeStyleArgument);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { closestOfType } from 'eslint-codemod-utils';
|
|
2
|
+
import { isSafeProperty } from './is-safe-property';
|
|
3
|
+
import { isSafeStyleObject } from './is-safe-style-object';
|
|
4
|
+
function isSafeKeyframePropertyValue(value) {
|
|
5
|
+
if (value.type !== 'ObjectExpression') {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return isSafeStyleObject(value);
|
|
9
|
+
}
|
|
10
|
+
export function isSafeKeyframes(keyframes) {
|
|
11
|
+
return keyframes.references.every(ref => {
|
|
12
|
+
const callExpression = closestOfType(ref.identifier, 'CallExpression');
|
|
13
|
+
if (!callExpression) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (callExpression.callee !== ref.identifier) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (callExpression.arguments.length !== 1) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
const argument = callExpression.arguments[0];
|
|
23
|
+
if (argument.type !== 'ObjectExpression') {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return argument.properties.every(property => isSafeProperty(property, isSafeKeyframePropertyValue));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function hasSafeKey(property) {
|
|
2
|
+
if (property.computed) {
|
|
3
|
+
return property.key.type === 'Literal';
|
|
4
|
+
}
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
export function isSafeProperty(property, isSafePropertyValue) {
|
|
8
|
+
if (property.type === 'SpreadElement') {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (property.method || property.shorthand || property.kind !== 'init') {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (!hasSafeKey(property)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return isSafePropertyValue(property.value);
|
|
18
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isSafeStyleObject } from './is-safe-style-object';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Determines if a style argument is safe for auto-fix conversion.
|
|
5
|
+
*/
|
|
6
|
+
export function isSafeStyleArgument(arg) {
|
|
7
|
+
if (arg.type === 'ObjectExpression') {
|
|
8
|
+
return isSafeStyleObject(arg);
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isSafeProperty } from './is-safe-property';
|
|
2
|
+
function isSafeStyleValue(value) {
|
|
3
|
+
if (value.type === 'Literal') {
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
export function isSafeStyleObject(object) {
|
|
9
|
+
return object.properties.every(property => isSafeProperty(property, isSafeStyleValue));
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { closestOfType } from 'eslint-codemod-utils';
|
|
2
|
+
import { isSafeStyleArgument } from './is-safe-style-argument';
|
|
3
|
+
export function isSafeStyled(styled) {
|
|
4
|
+
return styled.references.every(ref => {
|
|
5
|
+
const callExpression = closestOfType(ref.identifier, 'CallExpression');
|
|
6
|
+
if (!callExpression) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* If it's not in the form `styled.tagName()`
|
|
12
|
+
* then we consider it unsafe to auto-fix.
|
|
13
|
+
*/
|
|
14
|
+
if (callExpression.callee.type !== 'MemberExpression' || callExpression.callee.object !== ref.identifier) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return callExpression.arguments.every(isSafeStyleArgument);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
2
|
+
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
3
|
+
import { isSafeCss } from './is-safe-css';
|
|
4
|
+
import { isSafeKeyframes } from './is-safe-keyframes';
|
|
5
|
+
export function isSafeUsage({
|
|
6
|
+
context,
|
|
7
|
+
specifier,
|
|
8
|
+
supportedImports
|
|
9
|
+
}) {
|
|
10
|
+
if (!('name' in specifier.imported)) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const importName = specifier.imported.name;
|
|
14
|
+
if (!supportedImports.has(importName)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (importName === 'css') {
|
|
18
|
+
const css = findVariable({
|
|
19
|
+
identifier: specifier.local,
|
|
20
|
+
sourceCode: getSourceCode(context)
|
|
21
|
+
});
|
|
22
|
+
return css !== null && isSafeCss(css);
|
|
23
|
+
}
|
|
24
|
+
if (importName === 'keyframes') {
|
|
25
|
+
const keyframes = findVariable({
|
|
26
|
+
identifier: specifier.local,
|
|
27
|
+
sourceCode: getSourceCode(context)
|
|
28
|
+
});
|
|
29
|
+
return keyframes !== null && isSafeKeyframes(keyframes);
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
@@ -5,12 +5,6 @@ export function getFirstImportFromSource(context, source) {
|
|
|
5
5
|
function isImportDeclaration(node) {
|
|
6
6
|
return node.type === 'ImportDeclaration';
|
|
7
7
|
}
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
export function isImportDefaultSpecifier(specifier) {
|
|
12
|
-
return specifier.type === 'ImportDefaultSpecifier';
|
|
13
|
-
}
|
|
14
|
-
export function isImportNamespaceSpecifier(specifier) {
|
|
15
|
-
return specifier.type === 'ImportNamespaceSpecifier';
|
|
16
|
-
}
|
|
8
|
+
export { isImportSpecifier } from './is-import-specifier';
|
|
9
|
+
export { isImportDefaultSpecifier } from './is-import-default-specifier';
|
|
10
|
+
export { isImportNamespaceSpecifier } from './is-import-namespace-specifier';
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { getCreateLintRule
|
|
2
|
-
|
|
1
|
+
import { getCreateLintRule } from '@atlaskit/eslint-utils/create-rule';
|
|
2
|
+
import { getRuleUrl } from './get-rule-url';
|
|
3
3
|
/**
|
|
4
4
|
* Tiny wrapped over the ESLint rule module type that ensures
|
|
5
5
|
* there is a docs link to our ESLint plugin documentation page,
|
|
6
6
|
* as well as improving type support.
|
|
7
7
|
*/
|
|
8
8
|
export const createLintRule = getCreateLintRule(getRuleUrl);
|
|
9
|
-
export
|
|
10
|
-
const name = getPathSafeName(ruleName);
|
|
11
|
-
return `https://atlassian.design/components/eslint-plugin-ui-styling-standard/${name}/usage`;
|
|
12
|
-
}
|
|
9
|
+
export { getRuleUrl } from './get-rule-url';
|
|
@@ -5,7 +5,7 @@ import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
|
5
5
|
import { hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
6
6
|
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
7
7
|
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
8
|
-
|
|
8
|
+
var rule = createLintRuleWithTypedConfig({
|
|
9
9
|
meta: {
|
|
10
10
|
name: 'no-important-styles',
|
|
11
11
|
docs: {
|
|
@@ -31,7 +31,7 @@ function isAllowedSelector(selector) {
|
|
|
31
31
|
return isHeadAllowed && isTailAllowed;
|
|
32
32
|
}
|
|
33
33
|
var cssSelectorProcessor = cssSelectorParser();
|
|
34
|
-
|
|
34
|
+
var rule = createLintRuleWithTypedConfig({
|
|
35
35
|
meta: {
|
|
36
36
|
name: 'no-nested-selectors',
|
|
37
37
|
docs: {
|