@atlaskit/eslint-plugin-ui-styling-standard 0.14.1 → 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 +22 -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/atlaskit-theme/index.js +10 -4
- 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/atlaskit-theme/index.js +10 -4
- 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/atlaskit-theme/index.js +10 -4
- 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/atlaskit-theme/__tests__/test.ts +11 -0
- package/src/rules/atlaskit-theme/index.ts +10 -4
- 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,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
|
|
9
|
+
var _schema = require("@atlaskit/eslint-utils/schema");
|
|
10
|
+
var _walkStyleProperties = require("@atlaskit/eslint-utils/walk-style-properties");
|
|
11
|
+
var _createRuleWithTypedConfig = require("../utils/create-rule-with-typed-config");
|
|
12
|
+
var _constants = require("./constants");
|
|
13
|
+
var _lintSelector = require("./lint-selector");
|
|
14
|
+
var _walkCssMap = require("./walk-css-map");
|
|
15
|
+
var cssSelectorProcessor = (0, _postcssSelectorParser.default)();
|
|
16
|
+
var rule = (0, _createRuleWithTypedConfig.createLintRuleWithTypedConfig)({
|
|
17
|
+
meta: {
|
|
18
|
+
name: 'no-unsafe-selectors',
|
|
19
|
+
docs: {
|
|
20
|
+
description: 'Disallows use of nested styles in `css` functions.',
|
|
21
|
+
recommended: true,
|
|
22
|
+
severity: 'warn'
|
|
23
|
+
},
|
|
24
|
+
fixable: 'code',
|
|
25
|
+
hasSuggestions: true,
|
|
26
|
+
messages: {
|
|
27
|
+
/**
|
|
28
|
+
* Selector messages
|
|
29
|
+
*/
|
|
30
|
+
'no-ambiguous-pseudos': 'Pseudo-classes and pseudo-elements without a leading selector are ambiguous. Use a more explicit selector.',
|
|
31
|
+
'no-increased-specificity': 'Do not chain the nesting selector.',
|
|
32
|
+
'no-restricted-pseudos': 'The {{pseudo}} pseudo is not allowed.',
|
|
33
|
+
'no-legacy-pseudo-element-syntax': 'Use a double colon for pseudo-elements. The single colon syntax is not supported for all pseudo-elements.',
|
|
34
|
+
'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.",
|
|
35
|
+
'no-selectors-object': 'Do not use the selectors object. Both nested and advanced selectors should be avoided.',
|
|
36
|
+
/**
|
|
37
|
+
* At-rule messages
|
|
38
|
+
*/
|
|
39
|
+
'no-keyframes-at-rules': 'Use the CSS-in-JS `keyframes` API instead of `@keyframes` at-rules.',
|
|
40
|
+
'no-restricted-at-rules': '{{atRule}} at-rule is not allowed.',
|
|
41
|
+
'no-grouped-at-rules': 'Do not group at-rules. Write flattened at-rules instead.',
|
|
42
|
+
/**
|
|
43
|
+
* Suggestion messages
|
|
44
|
+
*/
|
|
45
|
+
'insert-nesting-selector': 'Insert a nesting selector `&` to target the element itself. This is usually the intended behavior.'
|
|
46
|
+
},
|
|
47
|
+
schema: {
|
|
48
|
+
type: 'object',
|
|
49
|
+
properties: {
|
|
50
|
+
importSources: _schema.importSources,
|
|
51
|
+
shouldAlwaysInsertNestingSelectorForAmbiguousPseudos: {
|
|
52
|
+
type: 'boolean',
|
|
53
|
+
default: true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
additionalProperties: false
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
create: function create(context, config) {
|
|
60
|
+
return {
|
|
61
|
+
Program: function Program(program) {
|
|
62
|
+
(0, _walkCssMap.walkCssMap)({
|
|
63
|
+
context: context,
|
|
64
|
+
program: program,
|
|
65
|
+
importSources: config.importSources,
|
|
66
|
+
visitor: function visitor(property) {
|
|
67
|
+
var type = property.type,
|
|
68
|
+
node = property.node;
|
|
69
|
+
if (type === 'grouped-at-rules') {
|
|
70
|
+
context.report({
|
|
71
|
+
node: node.key,
|
|
72
|
+
messageId: 'no-grouped-at-rules'
|
|
73
|
+
});
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (type === 'selectors') {
|
|
77
|
+
context.report({
|
|
78
|
+
node: node.key,
|
|
79
|
+
messageId: 'no-selectors-object'
|
|
80
|
+
});
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
CallExpression: function (_CallExpression) {
|
|
87
|
+
function CallExpression(_x) {
|
|
88
|
+
return _CallExpression.apply(this, arguments);
|
|
89
|
+
}
|
|
90
|
+
CallExpression.toString = function () {
|
|
91
|
+
return _CallExpression.toString();
|
|
92
|
+
};
|
|
93
|
+
return CallExpression;
|
|
94
|
+
}(function (node) {
|
|
95
|
+
var _context$getScope = context.getScope(),
|
|
96
|
+
references = _context$getScope.references;
|
|
97
|
+
(0, _walkStyleProperties.walkStyleProperties)(node, references, config.importSources, function (_ref) {
|
|
98
|
+
var key = _ref.key,
|
|
99
|
+
value = _ref.value;
|
|
100
|
+
/**
|
|
101
|
+
* If the value isn't an object expression then the key can't be a selector.
|
|
102
|
+
*
|
|
103
|
+
* This assumes all styles have to be inline, which is enforced by `no-unsafe-values`
|
|
104
|
+
*/
|
|
105
|
+
if (value.type !== 'ObjectExpression') {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Technically the key could be an identifier too, e.g.
|
|
111
|
+
*
|
|
112
|
+
* ```ts
|
|
113
|
+
* css({
|
|
114
|
+
* // This key is an identifier, not a literal
|
|
115
|
+
* selector: {}
|
|
116
|
+
* });
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* But an identifier couldn't violate anything in this rule,
|
|
120
|
+
* because it can't contain '@' or ':' characters.
|
|
121
|
+
*/
|
|
122
|
+
if (key.type !== 'Literal' || typeof key.value !== 'string') {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
var selectorText = key.value;
|
|
126
|
+
if (selectorText.includes('@')) {
|
|
127
|
+
lintAtRule({
|
|
128
|
+
context: context,
|
|
129
|
+
sourceNode: key,
|
|
130
|
+
atRule: selectorText
|
|
131
|
+
});
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
var selectorList = cssSelectorProcessor.astSync(selectorText);
|
|
136
|
+
selectorList.nodes.forEach(function (selector) {
|
|
137
|
+
return (0, _lintSelector.lintSelector)({
|
|
138
|
+
context: context,
|
|
139
|
+
sourceNode: key,
|
|
140
|
+
selector: selector,
|
|
141
|
+
config: config
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
} catch (e) {
|
|
145
|
+
context.report({
|
|
146
|
+
node: key,
|
|
147
|
+
messageId: 'no-unparsable-selectors',
|
|
148
|
+
data: {
|
|
149
|
+
selectorText: selectorText
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
})
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
var _default = exports.default = rule;
|
|
159
|
+
function lintAtRule(_ref2) {
|
|
160
|
+
var context = _ref2.context,
|
|
161
|
+
sourceNode = _ref2.sourceNode,
|
|
162
|
+
atRule = _ref2.atRule;
|
|
163
|
+
var matches = atRule.trim().match(/^@[A-z-]+/);
|
|
164
|
+
if (!matches) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
var ruleName = matches[0];
|
|
168
|
+
if (_constants.ignoredAtRules.has(ruleName)) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (ruleName === '@keyframes') {
|
|
172
|
+
context.report({
|
|
173
|
+
node: sourceNode,
|
|
174
|
+
messageId: 'no-keyframes-at-rules'
|
|
175
|
+
});
|
|
176
|
+
} else {
|
|
177
|
+
context.report({
|
|
178
|
+
node: sourceNode,
|
|
179
|
+
messageId: 'no-restricted-at-rules',
|
|
180
|
+
data: {
|
|
181
|
+
atRule: ruleName
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.lintSelector = lintSelector;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
10
|
+
var _constants = require("./constants");
|
|
11
|
+
var _postcssSelectorParser = require("postcss-selector-parser");
|
|
12
|
+
var _sourcePositionUtils = require("./source-position-utils");
|
|
13
|
+
function lintSelector(args) {
|
|
14
|
+
checkNoAmbiguousPseudos(args);
|
|
15
|
+
checkNoRestrictedPseudos(args);
|
|
16
|
+
checkNoLegacyPseudoElementSyntax(args);
|
|
17
|
+
checkNoIncreasedSpecificity(args);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Ensures the use of a nesting selector `&` with pseudo-selectors.
|
|
22
|
+
*/
|
|
23
|
+
function checkNoAmbiguousPseudos(_ref) {
|
|
24
|
+
var context = _ref.context,
|
|
25
|
+
sourceNode = _ref.sourceNode,
|
|
26
|
+
selector = _ref.selector,
|
|
27
|
+
config = _ref.config;
|
|
28
|
+
if (selector.first.type !== 'pseudo') {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
var range = (0, _sourcePositionUtils.getRangeFromNode)({
|
|
32
|
+
node: selector.first,
|
|
33
|
+
sourceNode: sourceNode
|
|
34
|
+
});
|
|
35
|
+
var loc = (0, _sourcePositionUtils.getSourceLocationFromRange)(context, range);
|
|
36
|
+
if (config.shouldAlwaysInsertNestingSelectorForAmbiguousPseudos) {
|
|
37
|
+
context.report({
|
|
38
|
+
loc: loc,
|
|
39
|
+
messageId: 'no-ambiguous-pseudos',
|
|
40
|
+
fix: /*#__PURE__*/_regenerator.default.mark(function fix(fixer) {
|
|
41
|
+
return _regenerator.default.wrap(function fix$(_context) {
|
|
42
|
+
while (1) switch (_context.prev = _context.next) {
|
|
43
|
+
case 0:
|
|
44
|
+
_context.next = 2;
|
|
45
|
+
return fixer.insertTextBeforeRange(range, '&');
|
|
46
|
+
case 2:
|
|
47
|
+
case "end":
|
|
48
|
+
return _context.stop();
|
|
49
|
+
}
|
|
50
|
+
}, fix);
|
|
51
|
+
})
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
context.report({
|
|
55
|
+
loc: loc,
|
|
56
|
+
messageId: 'no-ambiguous-pseudos',
|
|
57
|
+
suggest: [{
|
|
58
|
+
messageId: 'insert-nesting-selector',
|
|
59
|
+
fix: /*#__PURE__*/_regenerator.default.mark(function fix(fixer) {
|
|
60
|
+
return _regenerator.default.wrap(function fix$(_context2) {
|
|
61
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
62
|
+
case 0:
|
|
63
|
+
_context2.next = 2;
|
|
64
|
+
return fixer.insertTextBeforeRange(range, '&');
|
|
65
|
+
case 2:
|
|
66
|
+
case "end":
|
|
67
|
+
return _context2.stop();
|
|
68
|
+
}
|
|
69
|
+
}, fix);
|
|
70
|
+
})
|
|
71
|
+
}]
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function checkNoRestrictedPseudos(_ref2) {
|
|
76
|
+
var context = _ref2.context,
|
|
77
|
+
sourceNode = _ref2.sourceNode,
|
|
78
|
+
selector = _ref2.selector;
|
|
79
|
+
selector.walkPseudos(function (pseudo) {
|
|
80
|
+
if (_constants.allowedPseudos.has(pseudo.value)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* If someone has written `:after` it is allowed,
|
|
86
|
+
* they've just used the legacy syntax.
|
|
87
|
+
*
|
|
88
|
+
* This will be caught by the `no-legacy-pseudo-element-syntax` check.
|
|
89
|
+
*/
|
|
90
|
+
if (_constants.legacyPseudoElements.has(pseudo.value) && _constants.allowedPseudos.has(":".concat(pseudo.value))) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (!_constants.allowedPseudos.has(pseudo.value)) {
|
|
94
|
+
var range = (0, _sourcePositionUtils.getRangeFromNode)({
|
|
95
|
+
node: pseudo,
|
|
96
|
+
sourceNode: sourceNode
|
|
97
|
+
});
|
|
98
|
+
var loc = (0, _sourcePositionUtils.getSourceLocationFromRange)(context, range);
|
|
99
|
+
context.report({
|
|
100
|
+
loc: loc,
|
|
101
|
+
messageId: 'no-restricted-pseudos',
|
|
102
|
+
data: {
|
|
103
|
+
pseudo: pseudo.value
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The original four pseudo-elements have a legacy single colon syntax.
|
|
112
|
+
*
|
|
113
|
+
* https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements
|
|
114
|
+
*/
|
|
115
|
+
function checkNoLegacyPseudoElementSyntax(_ref3) {
|
|
116
|
+
var context = _ref3.context,
|
|
117
|
+
sourceNode = _ref3.sourceNode,
|
|
118
|
+
selector = _ref3.selector;
|
|
119
|
+
selector.walkPseudos(function (pseudo) {
|
|
120
|
+
if (_constants.legacyPseudoElements.has(pseudo.value)) {
|
|
121
|
+
var range = (0, _sourcePositionUtils.getRangeFromNode)({
|
|
122
|
+
node: pseudo,
|
|
123
|
+
sourceNode: sourceNode
|
|
124
|
+
});
|
|
125
|
+
var loc = (0, _sourcePositionUtils.getSourceLocationFromRange)(context, range);
|
|
126
|
+
context.report({
|
|
127
|
+
loc: loc,
|
|
128
|
+
messageId: 'no-legacy-pseudo-element-syntax',
|
|
129
|
+
fix: /*#__PURE__*/_regenerator.default.mark(function fix(fixer) {
|
|
130
|
+
return _regenerator.default.wrap(function fix$(_context3) {
|
|
131
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
132
|
+
case 0:
|
|
133
|
+
_context3.next = 2;
|
|
134
|
+
return fixer.insertTextBeforeRange(range, ':');
|
|
135
|
+
case 2:
|
|
136
|
+
case "end":
|
|
137
|
+
return _context3.stop();
|
|
138
|
+
}
|
|
139
|
+
}, fix);
|
|
140
|
+
})
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function checkNoIncreasedSpecificity(_ref4) {
|
|
146
|
+
var context = _ref4.context,
|
|
147
|
+
sourceNode = _ref4.sourceNode,
|
|
148
|
+
selector = _ref4.selector;
|
|
149
|
+
selector.walkNesting(function (nesting) {
|
|
150
|
+
/**
|
|
151
|
+
* If it's not the start of a chain, then it's already been reported.
|
|
152
|
+
*/
|
|
153
|
+
if ((0, _postcssSelectorParser.isNesting)(nesting.prev())) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
var next = nesting.next();
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* If it is followed by something other than another nesting selector,
|
|
160
|
+
* then it isn't just there to increase specificity — it is actually necessary.
|
|
161
|
+
*/
|
|
162
|
+
if (next && !(0, _postcssSelectorParser.isNesting)(next)) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
var lastNesting = nesting;
|
|
166
|
+
while ((0, _postcssSelectorParser.isNesting)(next)) {
|
|
167
|
+
lastNesting = next;
|
|
168
|
+
next = next.next();
|
|
169
|
+
}
|
|
170
|
+
var _getRangeFromNode = (0, _sourcePositionUtils.getRangeFromNode)({
|
|
171
|
+
node: nesting,
|
|
172
|
+
sourceNode: sourceNode
|
|
173
|
+
}),
|
|
174
|
+
_getRangeFromNode2 = (0, _slicedToArray2.default)(_getRangeFromNode, 1),
|
|
175
|
+
start = _getRangeFromNode2[0];
|
|
176
|
+
var _getRangeFromNode3 = (0, _sourcePositionUtils.getRangeFromNode)({
|
|
177
|
+
node: lastNesting,
|
|
178
|
+
sourceNode: sourceNode
|
|
179
|
+
}),
|
|
180
|
+
_getRangeFromNode4 = (0, _slicedToArray2.default)(_getRangeFromNode3, 2),
|
|
181
|
+
_ = _getRangeFromNode4[0],
|
|
182
|
+
end = _getRangeFromNode4[1];
|
|
183
|
+
var loc = (0, _sourcePositionUtils.getSourceLocationFromRange)(context, [start, end]);
|
|
184
|
+
context.report({
|
|
185
|
+
loc: loc,
|
|
186
|
+
messageId: 'no-increased-specificity'
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getRangeFromNode = getRangeFromNode;
|
|
8
|
+
exports.getSourceLocationFromRange = getSourceLocationFromRange;
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
function getRangeFromNode(_ref) {
|
|
11
|
+
var node = _ref.node,
|
|
12
|
+
sourceNode = _ref.sourceNode;
|
|
13
|
+
/**
|
|
14
|
+
* The adjustment required to align the selector AST source position
|
|
15
|
+
* with the ESTree source position.
|
|
16
|
+
*/
|
|
17
|
+
var adjustment =
|
|
18
|
+
/**
|
|
19
|
+
* Using a non-null `!` is safe here because ESLint requires the parser to
|
|
20
|
+
* include a range value on nodes.
|
|
21
|
+
*
|
|
22
|
+
* https://eslint.org/docs/latest/extend/custom-parsers#all-nodes
|
|
23
|
+
*/
|
|
24
|
+
sourceNode.range[0] + (
|
|
25
|
+
/**
|
|
26
|
+
* We add +1 if it's a literal to account for the opening `'` or `"` character.
|
|
27
|
+
*/
|
|
28
|
+
sourceNode.type === 'Literal' ? 1 : 0);
|
|
29
|
+
var start = adjustment + node.sourceIndex;
|
|
30
|
+
var end = start + node.value.length;
|
|
31
|
+
return [start, end];
|
|
32
|
+
}
|
|
33
|
+
function getSourceLocationFromRange(context, _ref2) {
|
|
34
|
+
var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
|
|
35
|
+
start = _ref3[0],
|
|
36
|
+
end = _ref3[1];
|
|
37
|
+
var sourceCode = context.getSourceCode();
|
|
38
|
+
return {
|
|
39
|
+
start: sourceCode.getLocFromIndex(start),
|
|
40
|
+
end: sourceCode.getLocFromIndex(end)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.walkCssMap = walkCssMap;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
/**
|
|
10
|
+
* This util is intentionally not in `@atlaskit/eslint-utils` at this time.
|
|
11
|
+
*
|
|
12
|
+
* This is because the API is likely to change and should not be considered stable.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
function walkCssMap(_ref) {
|
|
16
|
+
var context = _ref.context,
|
|
17
|
+
importSources = _ref.importSources,
|
|
18
|
+
visitor = _ref.visitor;
|
|
19
|
+
var program = context.getSourceCode().ast;
|
|
20
|
+
var importDeclaration = program.body.find(function (node) {
|
|
21
|
+
return node.type === 'ImportDeclaration' && importSources.includes(node.source.value);
|
|
22
|
+
});
|
|
23
|
+
var specifier = importDeclaration === null || importDeclaration === void 0 ? void 0 : importDeclaration.specifiers.find(function (specifier) {
|
|
24
|
+
return specifier.type === 'ImportSpecifier' && specifier.imported.name === 'cssMap';
|
|
25
|
+
});
|
|
26
|
+
if (!specifier) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
var _context$getSourceCod = context.getSourceCode().scopeManager.getDeclaredVariables(specifier),
|
|
30
|
+
_context$getSourceCod2 = (0, _slicedToArray2.default)(_context$getSourceCod, 1),
|
|
31
|
+
variable = _context$getSourceCod2[0];
|
|
32
|
+
if (!variable) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
variable.references.forEach(function (reference) {
|
|
36
|
+
var identifier = reference.identifier;
|
|
37
|
+
var parent = identifier.parent;
|
|
38
|
+
if (parent.type !== 'CallExpression') {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
var variantMap = parent.arguments[0];
|
|
42
|
+
if (variantMap.type !== 'ObjectExpression') {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
walkCssMapVariantMap({
|
|
46
|
+
variantMap: variantMap,
|
|
47
|
+
visitor: visitor
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function walkCssMapVariantMap(_ref2) {
|
|
52
|
+
var variantMap = _ref2.variantMap,
|
|
53
|
+
visitor = _ref2.visitor;
|
|
54
|
+
variantMap.properties.forEach(function (property) {
|
|
55
|
+
if (property.type !== 'Property') {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
walkCssMapVariant({
|
|
59
|
+
variant: property,
|
|
60
|
+
visitor: visitor
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function walkCssMapVariant(_ref3) {
|
|
65
|
+
var variant = _ref3.variant,
|
|
66
|
+
visitor = _ref3.visitor;
|
|
67
|
+
visitor({
|
|
68
|
+
type: 'variant',
|
|
69
|
+
node: variant
|
|
70
|
+
});
|
|
71
|
+
if (variant.value.type !== 'ObjectExpression') {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
variant.value.properties.forEach(function (property) {
|
|
75
|
+
if (property.type !== 'Property') {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (property.value.type !== 'ObjectExpression') {
|
|
79
|
+
visitor({
|
|
80
|
+
type: 'declaration',
|
|
81
|
+
node: property
|
|
82
|
+
});
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
var keyValue = getKeyValue(property.key);
|
|
86
|
+
if (keyValue && /^@[A-z-]+$/.test(keyValue)) {
|
|
87
|
+
walkCssMapAtRuleGrouping({
|
|
88
|
+
atRuleGrouping: property,
|
|
89
|
+
visitor: visitor
|
|
90
|
+
});
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (keyValue === 'selectors') {
|
|
94
|
+
walkCssMapSelectors({
|
|
95
|
+
selectors: property,
|
|
96
|
+
visitor: visitor
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
walkStyleRuleset({
|
|
100
|
+
ruleset: property,
|
|
101
|
+
visitor: visitor
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function walkCssMapAtRuleGrouping(_ref4) {
|
|
106
|
+
var atRuleGrouping = _ref4.atRuleGrouping,
|
|
107
|
+
visitor = _ref4.visitor;
|
|
108
|
+
var atRule = getKeyValue(atRuleGrouping.key);
|
|
109
|
+
if (!atRule) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
visitor({
|
|
113
|
+
type: 'grouped-at-rules',
|
|
114
|
+
node: atRuleGrouping,
|
|
115
|
+
atRule: atRule
|
|
116
|
+
});
|
|
117
|
+
if (atRuleGrouping.value.type !== 'ObjectExpression') {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
atRuleGrouping.value.properties.forEach(function (property) {
|
|
121
|
+
if (property.type !== 'Property') {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
walkStyleRuleset({
|
|
125
|
+
ruleset: property,
|
|
126
|
+
visitor: visitor
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function walkCssMapSelectors(_ref5) {
|
|
131
|
+
var selectors = _ref5.selectors,
|
|
132
|
+
visitor = _ref5.visitor;
|
|
133
|
+
visitor({
|
|
134
|
+
type: 'selectors',
|
|
135
|
+
node: selectors
|
|
136
|
+
});
|
|
137
|
+
if (selectors.value.type !== 'ObjectExpression') {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
selectors.value.properties.forEach(function (property) {
|
|
141
|
+
if (property.type !== 'Property') {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
walkStyleRuleset({
|
|
145
|
+
ruleset: property,
|
|
146
|
+
visitor: visitor
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function walkStyleRuleset(_ref6) {
|
|
151
|
+
var ruleset = _ref6.ruleset,
|
|
152
|
+
visitor = _ref6.visitor;
|
|
153
|
+
visitor({
|
|
154
|
+
type: 'ruleset',
|
|
155
|
+
node: ruleset
|
|
156
|
+
});
|
|
157
|
+
if (ruleset.value.type !== 'ObjectExpression') {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
ruleset.value.properties.forEach(function (property) {
|
|
161
|
+
if (property.type !== 'Property') {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (property.value.type === 'ObjectExpression') {
|
|
165
|
+
walkStyleRuleset({
|
|
166
|
+
ruleset: property,
|
|
167
|
+
visitor: visitor
|
|
168
|
+
});
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
visitor({
|
|
172
|
+
type: 'declaration',
|
|
173
|
+
node: property
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function getKeyValue(key) {
|
|
178
|
+
if (key.type === 'Identifier') {
|
|
179
|
+
return key.name;
|
|
180
|
+
}
|
|
181
|
+
if (key.type === 'Literal') {
|
|
182
|
+
var _key$value$toString, _key$value;
|
|
183
|
+
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;
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
@@ -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
|
export default {
|
|
@@ -20,6 +20,7 @@ export default {
|
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
23
|
+
'@atlaskit/ui-styling-standard/no-unsafe-selectors': 'warn',
|
|
23
24
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
24
25
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
25
26
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
@@ -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
|
export default {
|
|
@@ -20,6 +20,7 @@ export default {
|
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
23
|
+
'@atlaskit/ui-styling-standard/no-unsafe-selectors': 'warn',
|
|
23
24
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
24
25
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
25
26
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
@@ -63,8 +63,11 @@ export const rule = createLintRule({
|
|
|
63
63
|
|
|
64
64
|
// Check if ancestor node is a call expression to Compiled
|
|
65
65
|
if (ancestors.some(ancestor => ancestor.type === 'CallExpression' && ancestor.callee && isCompiled(ancestor.callee, references, importSources))) {
|
|
66
|
-
//
|
|
67
|
-
|
|
66
|
+
// Ignore the fontFallback object as it contains strings to be used as token fallbacks
|
|
67
|
+
if ('name' in node && node.name !== 'fontFallback') {
|
|
68
|
+
// Check identifier for violations
|
|
69
|
+
checkIdentifier(node, context, references);
|
|
70
|
+
}
|
|
68
71
|
}
|
|
69
72
|
},
|
|
70
73
|
'TaggedTemplateExpression Identifier': node => {
|
|
@@ -75,8 +78,11 @@ export const rule = createLintRule({
|
|
|
75
78
|
|
|
76
79
|
// Check if ancestor node is a tagged template expression to Compiled
|
|
77
80
|
if (ancestors.some(ancestor => ancestor.type === 'TaggedTemplateExpression' && ancestor.tag && isCompiled(ancestor.tag, references, importSources))) {
|
|
78
|
-
//
|
|
79
|
-
|
|
81
|
+
// Ignore the fontFallback object as it contains strings to be used as token fallbacks
|
|
82
|
+
if ('name' in node && node.name !== 'fontFallback') {
|
|
83
|
+
// Check identifier for violations
|
|
84
|
+
checkIdentifier(node, context, references);
|
|
85
|
+
}
|
|
80
86
|
}
|
|
81
87
|
}
|
|
82
88
|
};
|
|
@@ -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::c907cf4b4e11348239dadaefebe80fca>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import atlaskitTheme from './atlaskit-theme';
|
|
@@ -17,6 +17,7 @@ import noImportantStyles from './no-important-styles';
|
|
|
17
17
|
import noImportedStyleValues from './no-imported-style-values';
|
|
18
18
|
import noNestedSelectors from './no-nested-selectors';
|
|
19
19
|
import noStyled from './no-styled';
|
|
20
|
+
import noUnsafeSelectors from './no-unsafe-selectors';
|
|
20
21
|
import noUnsafeValues from './no-unsafe-values';
|
|
21
22
|
import useCompiled from './use-compiled';
|
|
22
23
|
export default {
|
|
@@ -34,6 +35,7 @@ export default {
|
|
|
34
35
|
'no-imported-style-values': noImportedStyleValues,
|
|
35
36
|
'no-nested-selectors': noNestedSelectors,
|
|
36
37
|
'no-styled': noStyled,
|
|
38
|
+
'no-unsafe-selectors': noUnsafeSelectors,
|
|
37
39
|
'no-unsafe-values': noUnsafeValues,
|
|
38
40
|
'use-compiled': useCompiled
|
|
39
41
|
};
|