@atlaskit/eslint-plugin-ui-styling-standard 2.1.3 → 2.1.5

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +18 -18
  3. package/dist/cjs/rules/no-container-queries/index.js +62 -13
  4. package/dist/cjs/rules/no-important-styles/index.js +79 -99
  5. package/dist/cjs/rules/no-nested-selectors/index.js +46 -32
  6. package/dist/cjs/rules/no-unsafe-selectors/index.js +87 -84
  7. package/dist/cjs/rules/no-unsafe-selectors/lint-selector.js +140 -101
  8. package/dist/cjs/rules/no-unsafe-selectors/walk-css-map.js +20 -50
  9. package/dist/cjs/rules/utils/create-rule-with-typed-config.js +29 -10
  10. package/dist/cjs/rules/utils/is-simple-selector.js +70 -0
  11. package/dist/cjs/rules/utils/parse-selector.js +3 -4
  12. package/dist/cjs/rules/utils/style-calls.js +127 -0
  13. package/dist/cjs/rules/utils/walk-style-call-properties.js +50 -0
  14. package/dist/es2019/rules/no-container-queries/index.js +53 -14
  15. package/dist/es2019/rules/no-important-styles/index.js +79 -70
  16. package/dist/es2019/rules/no-nested-selectors/index.js +36 -34
  17. package/dist/es2019/rules/no-unsafe-selectors/index.js +67 -87
  18. package/dist/es2019/rules/no-unsafe-selectors/lint-selector.js +29 -23
  19. package/dist/es2019/rules/no-unsafe-selectors/walk-css-map.js +4 -30
  20. package/dist/es2019/rules/utils/create-rule-with-typed-config.js +30 -10
  21. package/dist/es2019/rules/utils/is-simple-selector.js +63 -0
  22. package/dist/es2019/rules/utils/parse-selector.js +3 -4
  23. package/dist/es2019/rules/utils/style-calls.js +89 -0
  24. package/dist/es2019/rules/utils/walk-style-call-properties.js +23 -0
  25. package/dist/esm/rules/no-container-queries/index.js +63 -14
  26. package/dist/esm/rules/no-important-styles/index.js +80 -100
  27. package/dist/esm/rules/no-nested-selectors/index.js +46 -32
  28. package/dist/esm/rules/no-unsafe-selectors/index.js +88 -85
  29. package/dist/esm/rules/no-unsafe-selectors/lint-selector.js +141 -102
  30. package/dist/esm/rules/no-unsafe-selectors/walk-css-map.js +19 -49
  31. package/dist/esm/rules/utils/create-rule-with-typed-config.js +30 -10
  32. package/dist/esm/rules/utils/is-simple-selector.js +64 -0
  33. package/dist/esm/rules/utils/parse-selector.js +3 -4
  34. package/dist/esm/rules/utils/style-calls.js +120 -0
  35. package/dist/esm/rules/utils/walk-style-call-properties.js +44 -0
  36. package/dist/types/rules/no-unsafe-selectors/walk-css-map.d.ts +1 -7
  37. package/dist/types/rules/utils/is-simple-selector.d.ts +11 -0
  38. package/dist/types/rules/utils/parse-selector.d.ts +1 -2
  39. package/dist/types/rules/utils/style-calls.d.ts +17 -0
  40. package/dist/types/rules/utils/walk-style-call-properties.d.ts +5 -0
  41. package/package.json +1 -1
@@ -0,0 +1,44 @@
1
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
2
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
3
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
4
+ export function walkStyleCallProperties(styleCall, visitor, options) {
5
+ var skipTopLevel = !(options !== null && options !== void 0 && options.includeTopLevel) && (styleCall.styleFunction === 'cssMap' || styleCall.styleFunction === 'keyframes');
6
+ var _iterator = _createForOfIteratorHelper(styleCall.node.arguments),
7
+ _step;
8
+ try {
9
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
10
+ var argument = _step.value;
11
+ if (argument.type === 'ObjectExpression') {
12
+ walkStyleObject(argument, visitor, skipTopLevel);
13
+ } else if (argument.type === 'ArrowFunctionExpression' && argument.expression && argument.body.type === 'ObjectExpression') {
14
+ walkStyleObject(argument.body, visitor, skipTopLevel);
15
+ }
16
+ }
17
+ } catch (err) {
18
+ _iterator.e(err);
19
+ } finally {
20
+ _iterator.f();
21
+ }
22
+ }
23
+ function walkStyleObject(object, visitor, skipVisitor) {
24
+ var _iterator2 = _createForOfIteratorHelper(object.properties),
25
+ _step2;
26
+ try {
27
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
28
+ var property = _step2.value;
29
+ if (property.type !== 'Property') {
30
+ continue;
31
+ }
32
+ if (!skipVisitor) {
33
+ visitor(property);
34
+ }
35
+ if (property.value.type === 'ObjectExpression') {
36
+ walkStyleObject(property.value, visitor, false);
37
+ }
38
+ }
39
+ } catch (err) {
40
+ _iterator2.e(err);
41
+ } finally {
42
+ _iterator2.f();
43
+ }
44
+ }
@@ -3,7 +3,6 @@
3
3
  *
4
4
  * This is because the API is likely to change and should not be considered stable.
5
5
  */
6
- import type { Rule } from 'eslint';
7
6
  import type * as ESTree from 'eslint-codemod-utils';
8
7
  type CssMapVisitorArgs = {
9
8
  type: 'variant' | 'declaration' | 'ruleset' | 'selectors';
@@ -14,10 +13,5 @@ type CssMapVisitorArgs = {
14
13
  atRule: string;
15
14
  };
16
15
  type CssMapVisitor = (args: CssMapVisitorArgs) => void;
17
- export declare function walkCssMap({ context, importSources, visitor, }: {
18
- context: Rule.RuleContext;
19
- program: ESTree.Program;
20
- importSources: string[];
21
- visitor: CssMapVisitor;
22
- }): void;
16
+ export declare function walkCssMapCall(call: ESTree.CallExpression, visitor: CssMapVisitor): void;
23
17
  export {};
@@ -0,0 +1,11 @@
1
+ type Options = {
2
+ allowedPseudos?: ReadonlySet<string>;
3
+ allowBareNesting?: boolean;
4
+ allowLeadingPseudo?: boolean;
5
+ };
6
+ /**
7
+ * Recognizes simple, parseable selector lists made only from nesting and non-functional pseudos.
8
+ * Returning false means the caller must use the full selector parser.
9
+ */
10
+ export declare function isSimpleSelector(selectorText: string, options?: Options): boolean;
11
+ export {};
@@ -3,8 +3,7 @@ import cssSelectorParser from 'postcss-selector-parser';
3
3
  declare const cssSelectorProcessor: ReturnType<typeof cssSelectorParser>;
4
4
  type ParsedSelector = ReturnType<typeof cssSelectorProcessor.astSync>;
5
5
  /**
6
- * Parse each selector once per linted source file. Return a clone so selector traversal state is
7
- * not shared between rules.
6
+ * Parse each selector once per linted source file. Consumers treat the returned AST as read-only.
8
7
  */
9
8
  export declare function parseSelector(context: Rule.RuleContext, selectorText: string): ParsedSelector;
10
9
  export {};
@@ -0,0 +1,17 @@
1
+ import type { Rule } from 'eslint';
2
+ import type * as ESTree from 'eslint-codemod-utils';
3
+ type StyleFunctionName = 'css' | 'cssMap' | 'keyframes' | 'styled' | 'xcss';
4
+ export type StyleCall = {
5
+ importSource: string;
6
+ node: ESTree.CallExpression;
7
+ styleFunction: StyleFunctionName;
8
+ };
9
+ /**
10
+ * Visit imported style calls without resolving every CallExpression against its current scope.
11
+ *
12
+ * ESLint has already linked import bindings to all of their references. Building this index once
13
+ * per source file makes each styling rule proportional to the number of style calls instead of the
14
+ * number of all calls in the file.
15
+ */
16
+ export declare function getStyleCalls(context: Rule.RuleContext): readonly StyleCall[];
17
+ export {};
@@ -0,0 +1,5 @@
1
+ import type * as ESTree from 'eslint-codemod-utils';
2
+ import type { StyleCall } from './style-calls';
3
+ export declare function walkStyleCallProperties(styleCall: StyleCall, visitor: (property: ESTree.Property) => void, options?: {
4
+ includeTopLevel?: boolean;
5
+ }): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-ui-styling-standard",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
4
4
  "author": "Atlassian Pty Ltd",
5
5
  "description": "The eslint plugin to enforce and educate on Atlassian's UI Styling Standard",
6
6
  "license": "Apache-2.0",