@atlaskit/eslint-plugin-ui-styling-standard 0.14.2 → 0.15.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/CHANGELOG.md +13 -0
- package/README.md +1 -0
- package/afm-cc/tsconfig.json +10 -3
- package/afm-jira/tsconfig.json +28 -0
- package/constellation/index/overview.mdx +29 -28
- package/constellation/no-unsafe-selectors/usage.mdx +244 -0
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/index.codegen.js +3 -1
- package/dist/cjs/rules/no-unsafe-selectors/constants.js +30 -0
- package/dist/cjs/rules/no-unsafe-selectors/index.js +185 -0
- package/dist/cjs/rules/no-unsafe-selectors/lint-selector.js +189 -0
- package/dist/cjs/rules/no-unsafe-selectors/source-position-utils.js +42 -0
- package/dist/cjs/rules/no-unsafe-selectors/walk-css-map.js +186 -0
- package/dist/es2019/presets/all.codegen.js +2 -1
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/index.codegen.js +3 -1
- package/dist/es2019/rules/no-unsafe-selectors/constants.js +22 -0
- package/dist/es2019/rules/no-unsafe-selectors/index.js +173 -0
- package/dist/es2019/rules/no-unsafe-selectors/lint-selector.js +152 -0
- package/dist/es2019/rules/no-unsafe-selectors/source-position-utils.js +31 -0
- package/dist/es2019/rules/no-unsafe-selectors/walk-css-map.js +180 -0
- package/dist/esm/presets/all.codegen.js +2 -1
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/index.codegen.js +3 -1
- package/dist/esm/rules/no-unsafe-selectors/constants.js +24 -0
- package/dist/esm/rules/no-unsafe-selectors/index.js +178 -0
- package/dist/esm/rules/no-unsafe-selectors/lint-selector.js +182 -0
- package/dist/esm/rules/no-unsafe-selectors/source-position-utils.js +34 -0
- package/dist/esm/rules/no-unsafe-selectors/walk-css-map.js +179 -0
- package/dist/types/index.codegen.d.ts +2 -0
- package/dist/types/presets/all.codegen.d.ts +2 -1
- package/dist/types/presets/recommended.codegen.d.ts +2 -1
- package/dist/types/rules/index.codegen.d.ts +1 -0
- package/dist/types/rules/no-unsafe-selectors/constants.d.ts +23 -0
- package/dist/types/rules/no-unsafe-selectors/index.d.ts +3 -0
- package/dist/types/rules/no-unsafe-selectors/lint-selector.d.ts +13 -0
- package/dist/types/rules/no-unsafe-selectors/source-position-utils.d.ts +20 -0
- package/dist/types/rules/no-unsafe-selectors/walk-css-map.d.ts +23 -0
- package/dist/types-ts4.5/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
- package/dist/types-ts4.5/rules/no-unsafe-selectors/constants.d.ts +84 -0
- package/dist/types-ts4.5/rules/no-unsafe-selectors/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-unsafe-selectors/lint-selector.d.ts +13 -0
- package/dist/types-ts4.5/rules/no-unsafe-selectors/source-position-utils.d.ts +23 -0
- package/dist/types-ts4.5/rules/no-unsafe-selectors/walk-css-map.d.ts +23 -0
- package/package.json +6 -5
- package/scripts/codegen.tsx +3 -4
- package/src/presets/all.codegen.tsx +2 -1
- package/src/presets/recommended.codegen.tsx +2 -1
- package/src/rules/index.codegen.tsx +3 -1
- package/src/rules/no-classname-prop/index.tsx +1 -1
- package/src/rules/no-nested-selectors/index.tsx +1 -1
- package/src/rules/no-unsafe-selectors/README.md +232 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-ambiguous-pseudos.test.tsx +358 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +60 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +73 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +40 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +101 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +131 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +132 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +25 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +35 -0
- package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +238 -0
- package/src/rules/no-unsafe-selectors/constants.tsx +99 -0
- package/src/rules/no-unsafe-selectors/index.tsx +201 -0
- package/src/rules/no-unsafe-selectors/lint-selector.tsx +168 -0
- package/src/rules/no-unsafe-selectors/source-position-utils.tsx +55 -0
- package/src/rules/no-unsafe-selectors/walk-css-map.tsx +232 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import cssSelectorParser from 'postcss-selector-parser';
|
|
2
|
+
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
3
|
+
import { walkStyleProperties } from '@atlaskit/eslint-utils/walk-style-properties';
|
|
4
|
+
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
5
|
+
import { ignoredAtRules } from './constants';
|
|
6
|
+
import { lintSelector } from './lint-selector';
|
|
7
|
+
import { walkCssMap } from './walk-css-map';
|
|
8
|
+
var cssSelectorProcessor = cssSelectorParser();
|
|
9
|
+
var rule = createLintRuleWithTypedConfig({
|
|
10
|
+
meta: {
|
|
11
|
+
name: 'no-unsafe-selectors',
|
|
12
|
+
docs: {
|
|
13
|
+
description: 'Disallows use of nested styles in `css` functions.',
|
|
14
|
+
recommended: true,
|
|
15
|
+
severity: 'warn'
|
|
16
|
+
},
|
|
17
|
+
fixable: 'code',
|
|
18
|
+
hasSuggestions: true,
|
|
19
|
+
messages: {
|
|
20
|
+
/**
|
|
21
|
+
* Selector messages
|
|
22
|
+
*/
|
|
23
|
+
'no-ambiguous-pseudos': 'Pseudo-classes and pseudo-elements without a leading selector are ambiguous. Use a more explicit selector.',
|
|
24
|
+
'no-increased-specificity': 'Do not chain the nesting selector.',
|
|
25
|
+
'no-restricted-pseudos': 'The {{pseudo}} pseudo is not allowed.',
|
|
26
|
+
'no-legacy-pseudo-element-syntax': 'Use a double colon for pseudo-elements. The single colon syntax is not supported for all pseudo-elements.',
|
|
27
|
+
'no-unparsable-selectors': "The selector '{{selectorText}}' could not be parsed and is likely an authoring mistake. If you think this is an error reach out in #help-ui-styling-standard.",
|
|
28
|
+
'no-selectors-object': 'Do not use the selectors object. Both nested and advanced selectors should be avoided.',
|
|
29
|
+
/**
|
|
30
|
+
* At-rule messages
|
|
31
|
+
*/
|
|
32
|
+
'no-keyframes-at-rules': 'Use the CSS-in-JS `keyframes` API instead of `@keyframes` at-rules.',
|
|
33
|
+
'no-restricted-at-rules': '{{atRule}} at-rule is not allowed.',
|
|
34
|
+
'no-grouped-at-rules': 'Do not group at-rules. Write flattened at-rules instead.',
|
|
35
|
+
/**
|
|
36
|
+
* Suggestion messages
|
|
37
|
+
*/
|
|
38
|
+
'insert-nesting-selector': 'Insert a nesting selector `&` to target the element itself. This is usually the intended behavior.'
|
|
39
|
+
},
|
|
40
|
+
schema: {
|
|
41
|
+
type: 'object',
|
|
42
|
+
properties: {
|
|
43
|
+
importSources: importSources,
|
|
44
|
+
shouldAlwaysInsertNestingSelectorForAmbiguousPseudos: {
|
|
45
|
+
type: 'boolean',
|
|
46
|
+
default: true
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
additionalProperties: false
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
create: function create(context, config) {
|
|
53
|
+
return {
|
|
54
|
+
Program: function Program(program) {
|
|
55
|
+
walkCssMap({
|
|
56
|
+
context: context,
|
|
57
|
+
program: program,
|
|
58
|
+
importSources: config.importSources,
|
|
59
|
+
visitor: function visitor(property) {
|
|
60
|
+
var type = property.type,
|
|
61
|
+
node = property.node;
|
|
62
|
+
if (type === 'grouped-at-rules') {
|
|
63
|
+
context.report({
|
|
64
|
+
node: node.key,
|
|
65
|
+
messageId: 'no-grouped-at-rules'
|
|
66
|
+
});
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (type === 'selectors') {
|
|
70
|
+
context.report({
|
|
71
|
+
node: node.key,
|
|
72
|
+
messageId: 'no-selectors-object'
|
|
73
|
+
});
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
CallExpression: function (_CallExpression) {
|
|
80
|
+
function CallExpression(_x) {
|
|
81
|
+
return _CallExpression.apply(this, arguments);
|
|
82
|
+
}
|
|
83
|
+
CallExpression.toString = function () {
|
|
84
|
+
return _CallExpression.toString();
|
|
85
|
+
};
|
|
86
|
+
return CallExpression;
|
|
87
|
+
}(function (node) {
|
|
88
|
+
var _context$getScope = context.getScope(),
|
|
89
|
+
references = _context$getScope.references;
|
|
90
|
+
walkStyleProperties(node, references, config.importSources, function (_ref) {
|
|
91
|
+
var key = _ref.key,
|
|
92
|
+
value = _ref.value;
|
|
93
|
+
/**
|
|
94
|
+
* If the value isn't an object expression then the key can't be a selector.
|
|
95
|
+
*
|
|
96
|
+
* This assumes all styles have to be inline, which is enforced by `no-unsafe-values`
|
|
97
|
+
*/
|
|
98
|
+
if (value.type !== 'ObjectExpression') {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Technically the key could be an identifier too, e.g.
|
|
104
|
+
*
|
|
105
|
+
* ```ts
|
|
106
|
+
* css({
|
|
107
|
+
* // This key is an identifier, not a literal
|
|
108
|
+
* selector: {}
|
|
109
|
+
* });
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* But an identifier couldn't violate anything in this rule,
|
|
113
|
+
* because it can't contain '@' or ':' characters.
|
|
114
|
+
*/
|
|
115
|
+
if (key.type !== 'Literal' || typeof key.value !== 'string') {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
var selectorText = key.value;
|
|
119
|
+
if (selectorText.includes('@')) {
|
|
120
|
+
lintAtRule({
|
|
121
|
+
context: context,
|
|
122
|
+
sourceNode: key,
|
|
123
|
+
atRule: selectorText
|
|
124
|
+
});
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
var selectorList = cssSelectorProcessor.astSync(selectorText);
|
|
129
|
+
selectorList.nodes.forEach(function (selector) {
|
|
130
|
+
return lintSelector({
|
|
131
|
+
context: context,
|
|
132
|
+
sourceNode: key,
|
|
133
|
+
selector: selector,
|
|
134
|
+
config: config
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
} catch (e) {
|
|
138
|
+
context.report({
|
|
139
|
+
node: key,
|
|
140
|
+
messageId: 'no-unparsable-selectors',
|
|
141
|
+
data: {
|
|
142
|
+
selectorText: selectorText
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
})
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
export default rule;
|
|
152
|
+
function lintAtRule(_ref2) {
|
|
153
|
+
var context = _ref2.context,
|
|
154
|
+
sourceNode = _ref2.sourceNode,
|
|
155
|
+
atRule = _ref2.atRule;
|
|
156
|
+
var matches = atRule.trim().match(/^@[A-z-]+/);
|
|
157
|
+
if (!matches) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
var ruleName = matches[0];
|
|
161
|
+
if (ignoredAtRules.has(ruleName)) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (ruleName === '@keyframes') {
|
|
165
|
+
context.report({
|
|
166
|
+
node: sourceNode,
|
|
167
|
+
messageId: 'no-keyframes-at-rules'
|
|
168
|
+
});
|
|
169
|
+
} else {
|
|
170
|
+
context.report({
|
|
171
|
+
node: sourceNode,
|
|
172
|
+
messageId: 'no-restricted-at-rules',
|
|
173
|
+
data: {
|
|
174
|
+
atRule: ruleName
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import { allowedPseudos, legacyPseudoElements } from './constants';
|
|
4
|
+
import { isNesting } from 'postcss-selector-parser';
|
|
5
|
+
import { getRangeFromNode, getSourceLocationFromRange } from './source-position-utils';
|
|
6
|
+
export function lintSelector(args) {
|
|
7
|
+
checkNoAmbiguousPseudos(args);
|
|
8
|
+
checkNoRestrictedPseudos(args);
|
|
9
|
+
checkNoLegacyPseudoElementSyntax(args);
|
|
10
|
+
checkNoIncreasedSpecificity(args);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Ensures the use of a nesting selector `&` with pseudo-selectors.
|
|
15
|
+
*/
|
|
16
|
+
function checkNoAmbiguousPseudos(_ref) {
|
|
17
|
+
var context = _ref.context,
|
|
18
|
+
sourceNode = _ref.sourceNode,
|
|
19
|
+
selector = _ref.selector,
|
|
20
|
+
config = _ref.config;
|
|
21
|
+
if (selector.first.type !== 'pseudo') {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
var range = getRangeFromNode({
|
|
25
|
+
node: selector.first,
|
|
26
|
+
sourceNode: sourceNode
|
|
27
|
+
});
|
|
28
|
+
var loc = getSourceLocationFromRange(context, range);
|
|
29
|
+
if (config.shouldAlwaysInsertNestingSelectorForAmbiguousPseudos) {
|
|
30
|
+
context.report({
|
|
31
|
+
loc: loc,
|
|
32
|
+
messageId: 'no-ambiguous-pseudos',
|
|
33
|
+
fix: /*#__PURE__*/_regeneratorRuntime.mark(function fix(fixer) {
|
|
34
|
+
return _regeneratorRuntime.wrap(function fix$(_context) {
|
|
35
|
+
while (1) switch (_context.prev = _context.next) {
|
|
36
|
+
case 0:
|
|
37
|
+
_context.next = 2;
|
|
38
|
+
return fixer.insertTextBeforeRange(range, '&');
|
|
39
|
+
case 2:
|
|
40
|
+
case "end":
|
|
41
|
+
return _context.stop();
|
|
42
|
+
}
|
|
43
|
+
}, fix);
|
|
44
|
+
})
|
|
45
|
+
});
|
|
46
|
+
} else {
|
|
47
|
+
context.report({
|
|
48
|
+
loc: loc,
|
|
49
|
+
messageId: 'no-ambiguous-pseudos',
|
|
50
|
+
suggest: [{
|
|
51
|
+
messageId: 'insert-nesting-selector',
|
|
52
|
+
fix: /*#__PURE__*/_regeneratorRuntime.mark(function fix(fixer) {
|
|
53
|
+
return _regeneratorRuntime.wrap(function fix$(_context2) {
|
|
54
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
55
|
+
case 0:
|
|
56
|
+
_context2.next = 2;
|
|
57
|
+
return fixer.insertTextBeforeRange(range, '&');
|
|
58
|
+
case 2:
|
|
59
|
+
case "end":
|
|
60
|
+
return _context2.stop();
|
|
61
|
+
}
|
|
62
|
+
}, fix);
|
|
63
|
+
})
|
|
64
|
+
}]
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function checkNoRestrictedPseudos(_ref2) {
|
|
69
|
+
var context = _ref2.context,
|
|
70
|
+
sourceNode = _ref2.sourceNode,
|
|
71
|
+
selector = _ref2.selector;
|
|
72
|
+
selector.walkPseudos(function (pseudo) {
|
|
73
|
+
if (allowedPseudos.has(pseudo.value)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* If someone has written `:after` it is allowed,
|
|
79
|
+
* they've just used the legacy syntax.
|
|
80
|
+
*
|
|
81
|
+
* This will be caught by the `no-legacy-pseudo-element-syntax` check.
|
|
82
|
+
*/
|
|
83
|
+
if (legacyPseudoElements.has(pseudo.value) && allowedPseudos.has(":".concat(pseudo.value))) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (!allowedPseudos.has(pseudo.value)) {
|
|
87
|
+
var range = getRangeFromNode({
|
|
88
|
+
node: pseudo,
|
|
89
|
+
sourceNode: sourceNode
|
|
90
|
+
});
|
|
91
|
+
var loc = getSourceLocationFromRange(context, range);
|
|
92
|
+
context.report({
|
|
93
|
+
loc: loc,
|
|
94
|
+
messageId: 'no-restricted-pseudos',
|
|
95
|
+
data: {
|
|
96
|
+
pseudo: pseudo.value
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The original four pseudo-elements have a legacy single colon syntax.
|
|
105
|
+
*
|
|
106
|
+
* https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements
|
|
107
|
+
*/
|
|
108
|
+
function checkNoLegacyPseudoElementSyntax(_ref3) {
|
|
109
|
+
var context = _ref3.context,
|
|
110
|
+
sourceNode = _ref3.sourceNode,
|
|
111
|
+
selector = _ref3.selector;
|
|
112
|
+
selector.walkPseudos(function (pseudo) {
|
|
113
|
+
if (legacyPseudoElements.has(pseudo.value)) {
|
|
114
|
+
var range = getRangeFromNode({
|
|
115
|
+
node: pseudo,
|
|
116
|
+
sourceNode: sourceNode
|
|
117
|
+
});
|
|
118
|
+
var loc = getSourceLocationFromRange(context, range);
|
|
119
|
+
context.report({
|
|
120
|
+
loc: loc,
|
|
121
|
+
messageId: 'no-legacy-pseudo-element-syntax',
|
|
122
|
+
fix: /*#__PURE__*/_regeneratorRuntime.mark(function fix(fixer) {
|
|
123
|
+
return _regeneratorRuntime.wrap(function fix$(_context3) {
|
|
124
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
125
|
+
case 0:
|
|
126
|
+
_context3.next = 2;
|
|
127
|
+
return fixer.insertTextBeforeRange(range, ':');
|
|
128
|
+
case 2:
|
|
129
|
+
case "end":
|
|
130
|
+
return _context3.stop();
|
|
131
|
+
}
|
|
132
|
+
}, fix);
|
|
133
|
+
})
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function checkNoIncreasedSpecificity(_ref4) {
|
|
139
|
+
var context = _ref4.context,
|
|
140
|
+
sourceNode = _ref4.sourceNode,
|
|
141
|
+
selector = _ref4.selector;
|
|
142
|
+
selector.walkNesting(function (nesting) {
|
|
143
|
+
/**
|
|
144
|
+
* If it's not the start of a chain, then it's already been reported.
|
|
145
|
+
*/
|
|
146
|
+
if (isNesting(nesting.prev())) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
var next = nesting.next();
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* If it is followed by something other than another nesting selector,
|
|
153
|
+
* then it isn't just there to increase specificity — it is actually necessary.
|
|
154
|
+
*/
|
|
155
|
+
if (next && !isNesting(next)) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
var lastNesting = nesting;
|
|
159
|
+
while (isNesting(next)) {
|
|
160
|
+
lastNesting = next;
|
|
161
|
+
next = next.next();
|
|
162
|
+
}
|
|
163
|
+
var _getRangeFromNode = getRangeFromNode({
|
|
164
|
+
node: nesting,
|
|
165
|
+
sourceNode: sourceNode
|
|
166
|
+
}),
|
|
167
|
+
_getRangeFromNode2 = _slicedToArray(_getRangeFromNode, 1),
|
|
168
|
+
start = _getRangeFromNode2[0];
|
|
169
|
+
var _getRangeFromNode3 = getRangeFromNode({
|
|
170
|
+
node: lastNesting,
|
|
171
|
+
sourceNode: sourceNode
|
|
172
|
+
}),
|
|
173
|
+
_getRangeFromNode4 = _slicedToArray(_getRangeFromNode3, 2),
|
|
174
|
+
_ = _getRangeFromNode4[0],
|
|
175
|
+
end = _getRangeFromNode4[1];
|
|
176
|
+
var loc = getSourceLocationFromRange(context, [start, end]);
|
|
177
|
+
context.report({
|
|
178
|
+
loc: loc,
|
|
179
|
+
messageId: 'no-increased-specificity'
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
export function getRangeFromNode(_ref) {
|
|
3
|
+
var node = _ref.node,
|
|
4
|
+
sourceNode = _ref.sourceNode;
|
|
5
|
+
/**
|
|
6
|
+
* The adjustment required to align the selector AST source position
|
|
7
|
+
* with the ESTree source position.
|
|
8
|
+
*/
|
|
9
|
+
var adjustment =
|
|
10
|
+
/**
|
|
11
|
+
* Using a non-null `!` is safe here because ESLint requires the parser to
|
|
12
|
+
* include a range value on nodes.
|
|
13
|
+
*
|
|
14
|
+
* https://eslint.org/docs/latest/extend/custom-parsers#all-nodes
|
|
15
|
+
*/
|
|
16
|
+
sourceNode.range[0] + (
|
|
17
|
+
/**
|
|
18
|
+
* We add +1 if it's a literal to account for the opening `'` or `"` character.
|
|
19
|
+
*/
|
|
20
|
+
sourceNode.type === 'Literal' ? 1 : 0);
|
|
21
|
+
var start = adjustment + node.sourceIndex;
|
|
22
|
+
var end = start + node.value.length;
|
|
23
|
+
return [start, end];
|
|
24
|
+
}
|
|
25
|
+
export function getSourceLocationFromRange(context, _ref2) {
|
|
26
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
27
|
+
start = _ref3[0],
|
|
28
|
+
end = _ref3[1];
|
|
29
|
+
var sourceCode = context.getSourceCode();
|
|
30
|
+
return {
|
|
31
|
+
start: sourceCode.getLocFromIndex(start),
|
|
32
|
+
end: sourceCode.getLocFromIndex(end)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
/**
|
|
3
|
+
* This util is intentionally not in `@atlaskit/eslint-utils` at this time.
|
|
4
|
+
*
|
|
5
|
+
* This is because the API is likely to change and should not be considered stable.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export function walkCssMap(_ref) {
|
|
9
|
+
var context = _ref.context,
|
|
10
|
+
importSources = _ref.importSources,
|
|
11
|
+
visitor = _ref.visitor;
|
|
12
|
+
var program = context.getSourceCode().ast;
|
|
13
|
+
var importDeclaration = program.body.find(function (node) {
|
|
14
|
+
return node.type === 'ImportDeclaration' && importSources.includes(node.source.value);
|
|
15
|
+
});
|
|
16
|
+
var specifier = importDeclaration === null || importDeclaration === void 0 ? void 0 : importDeclaration.specifiers.find(function (specifier) {
|
|
17
|
+
return specifier.type === 'ImportSpecifier' && specifier.imported.name === 'cssMap';
|
|
18
|
+
});
|
|
19
|
+
if (!specifier) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
var _context$getSourceCod = context.getSourceCode().scopeManager.getDeclaredVariables(specifier),
|
|
23
|
+
_context$getSourceCod2 = _slicedToArray(_context$getSourceCod, 1),
|
|
24
|
+
variable = _context$getSourceCod2[0];
|
|
25
|
+
if (!variable) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
variable.references.forEach(function (reference) {
|
|
29
|
+
var identifier = reference.identifier;
|
|
30
|
+
var parent = identifier.parent;
|
|
31
|
+
if (parent.type !== 'CallExpression') {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
var variantMap = parent.arguments[0];
|
|
35
|
+
if (variantMap.type !== 'ObjectExpression') {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
walkCssMapVariantMap({
|
|
39
|
+
variantMap: variantMap,
|
|
40
|
+
visitor: visitor
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function walkCssMapVariantMap(_ref2) {
|
|
45
|
+
var variantMap = _ref2.variantMap,
|
|
46
|
+
visitor = _ref2.visitor;
|
|
47
|
+
variantMap.properties.forEach(function (property) {
|
|
48
|
+
if (property.type !== 'Property') {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
walkCssMapVariant({
|
|
52
|
+
variant: property,
|
|
53
|
+
visitor: visitor
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function walkCssMapVariant(_ref3) {
|
|
58
|
+
var variant = _ref3.variant,
|
|
59
|
+
visitor = _ref3.visitor;
|
|
60
|
+
visitor({
|
|
61
|
+
type: 'variant',
|
|
62
|
+
node: variant
|
|
63
|
+
});
|
|
64
|
+
if (variant.value.type !== 'ObjectExpression') {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
variant.value.properties.forEach(function (property) {
|
|
68
|
+
if (property.type !== 'Property') {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (property.value.type !== 'ObjectExpression') {
|
|
72
|
+
visitor({
|
|
73
|
+
type: 'declaration',
|
|
74
|
+
node: property
|
|
75
|
+
});
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
var keyValue = getKeyValue(property.key);
|
|
79
|
+
if (keyValue && /^@[A-z-]+$/.test(keyValue)) {
|
|
80
|
+
walkCssMapAtRuleGrouping({
|
|
81
|
+
atRuleGrouping: property,
|
|
82
|
+
visitor: visitor
|
|
83
|
+
});
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (keyValue === 'selectors') {
|
|
87
|
+
walkCssMapSelectors({
|
|
88
|
+
selectors: property,
|
|
89
|
+
visitor: visitor
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
walkStyleRuleset({
|
|
93
|
+
ruleset: property,
|
|
94
|
+
visitor: visitor
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function walkCssMapAtRuleGrouping(_ref4) {
|
|
99
|
+
var atRuleGrouping = _ref4.atRuleGrouping,
|
|
100
|
+
visitor = _ref4.visitor;
|
|
101
|
+
var atRule = getKeyValue(atRuleGrouping.key);
|
|
102
|
+
if (!atRule) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
visitor({
|
|
106
|
+
type: 'grouped-at-rules',
|
|
107
|
+
node: atRuleGrouping,
|
|
108
|
+
atRule: atRule
|
|
109
|
+
});
|
|
110
|
+
if (atRuleGrouping.value.type !== 'ObjectExpression') {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
atRuleGrouping.value.properties.forEach(function (property) {
|
|
114
|
+
if (property.type !== 'Property') {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
walkStyleRuleset({
|
|
118
|
+
ruleset: property,
|
|
119
|
+
visitor: visitor
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function walkCssMapSelectors(_ref5) {
|
|
124
|
+
var selectors = _ref5.selectors,
|
|
125
|
+
visitor = _ref5.visitor;
|
|
126
|
+
visitor({
|
|
127
|
+
type: 'selectors',
|
|
128
|
+
node: selectors
|
|
129
|
+
});
|
|
130
|
+
if (selectors.value.type !== 'ObjectExpression') {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
selectors.value.properties.forEach(function (property) {
|
|
134
|
+
if (property.type !== 'Property') {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
walkStyleRuleset({
|
|
138
|
+
ruleset: property,
|
|
139
|
+
visitor: visitor
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function walkStyleRuleset(_ref6) {
|
|
144
|
+
var ruleset = _ref6.ruleset,
|
|
145
|
+
visitor = _ref6.visitor;
|
|
146
|
+
visitor({
|
|
147
|
+
type: 'ruleset',
|
|
148
|
+
node: ruleset
|
|
149
|
+
});
|
|
150
|
+
if (ruleset.value.type !== 'ObjectExpression') {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
ruleset.value.properties.forEach(function (property) {
|
|
154
|
+
if (property.type !== 'Property') {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (property.value.type === 'ObjectExpression') {
|
|
158
|
+
walkStyleRuleset({
|
|
159
|
+
ruleset: property,
|
|
160
|
+
visitor: visitor
|
|
161
|
+
});
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
visitor({
|
|
165
|
+
type: 'declaration',
|
|
166
|
+
node: property
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function getKeyValue(key) {
|
|
171
|
+
if (key.type === 'Identifier') {
|
|
172
|
+
return key.name;
|
|
173
|
+
}
|
|
174
|
+
if (key.type === 'Literal') {
|
|
175
|
+
var _key$value$toString, _key$value;
|
|
176
|
+
return (_key$value$toString = (_key$value = key.value) === null || _key$value === void 0 ? void 0 : _key$value.toString()) !== null && _key$value$toString !== void 0 ? _key$value$toString : null;
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
@@ -17,6 +17,7 @@ export declare const configs: {
|
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
18
18
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
20
|
+
'@atlaskit/ui-styling-standard/no-unsafe-selectors': string;
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
21
22
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
22
23
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -58,6 +59,7 @@ export declare const configs: {
|
|
|
58
59
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
59
60
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
60
61
|
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
62
|
+
'@atlaskit/ui-styling-standard/no-unsafe-selectors': string;
|
|
61
63
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
62
64
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
63
65
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::a4ab25dd4ce24b183125bfbc709e3943>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -20,6 +20,7 @@ declare const _default: {
|
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
23
|
+
'@atlaskit/ui-styling-standard/no-unsafe-selectors': string;
|
|
23
24
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
24
25
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
25
26
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::a4ab25dd4ce24b183125bfbc709e3943>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -20,6 +20,7 @@ declare const _default: {
|
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
23
|
+
'@atlaskit/ui-styling-standard/no-unsafe-selectors': string;
|
|
23
24
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
24
25
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
25
26
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -13,6 +13,7 @@ declare const _default: {
|
|
|
13
13
|
'no-imported-style-values': import("eslint").Rule.RuleModule;
|
|
14
14
|
'no-nested-selectors': import("eslint").Rule.RuleModule;
|
|
15
15
|
'no-styled': import("eslint").Rule.RuleModule;
|
|
16
|
+
'no-unsafe-selectors': import("eslint").Rule.RuleModule;
|
|
16
17
|
'no-unsafe-values': import("eslint").Rule.RuleModule;
|
|
17
18
|
'use-compiled': import("eslint").Rule.RuleModule;
|
|
18
19
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CSSPseudos } from '@compiled/react';
|
|
2
|
+
/**
|
|
3
|
+
* Validation approach from
|
|
4
|
+
* https://stackoverflow.com/a/71236280
|
|
5
|
+
*/
|
|
6
|
+
type Validate<T extends true> = T;
|
|
7
|
+
type HasAllUnique<Tuple, Union, Seen = never> = Tuple extends readonly [
|
|
8
|
+
infer Head,
|
|
9
|
+
...infer Tail
|
|
10
|
+
] ? Head extends Seen ? {
|
|
11
|
+
ERROR: ['The following key appears more than once in the tuple:', Head];
|
|
12
|
+
} : HasAllUnique<Tail, Exclude<Union, Head>, Head | Seen> : [Union] extends [never] ? true : {
|
|
13
|
+
ERROR: ['Some keys are missing from the tuple:', Union];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Exporting this so it isn't considered unused.
|
|
17
|
+
*/
|
|
18
|
+
export type _ = Validate<HasAllUnique<typeof cssPseudos, CSSPseudos>>;
|
|
19
|
+
declare const cssPseudos: readonly ["&:active", "&:autofill", "&:blank", "&:checked", "&:default", "&:defined", "&:disabled", "&:empty", "&:enabled", "&:first", "&:focus", "&:focus-visible", "&:focus-within", "&:fullscreen", "&:hover", "&:in-range", "&:indeterminate", "&:invalid", "&:left", "&:link", "&:local-link", "&:optional", "&:out-of-range", "&:paused", "&:picture-in-picture", "&:placeholder-shown", "&:playing", "&:read-only", "&:read-write", "&:required", "&:right", "&:target", "&:user-invalid", "&:user-valid", "&:valid", "&:visited", "&::after", "&::backdrop", "&::before", "&::cue", "&::cue-region", "&::first-letter", "&::first-line", "&::grammar-error", "&::marker", "&::placeholder", "&::selection", "&::spelling-error", "&::target-text", "&::view-transition"];
|
|
20
|
+
export declare const allowedPseudos: Set<string>;
|
|
21
|
+
export declare const legacyPseudoElements: Set<string>;
|
|
22
|
+
export declare const ignoredAtRules: Set<string>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import type * as ESTree from 'eslint-codemod-utils';
|
|
3
|
+
import { type Selector } from 'postcss-selector-parser';
|
|
4
|
+
type CheckArgs = {
|
|
5
|
+
context: Rule.RuleContext;
|
|
6
|
+
sourceNode: ESTree.Node;
|
|
7
|
+
selector: Selector;
|
|
8
|
+
config: {
|
|
9
|
+
shouldAlwaysInsertNestingSelectorForAmbiguousPseudos: boolean;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare function lintSelector(args: CheckArgs): void;
|
|
13
|
+
export {};
|