@atlaskit/eslint-plugin-ui-styling-standard 2.1.2 → 2.1.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +18 -18
  3. package/dist/cjs/rules/no-important-styles/index.js +79 -99
  4. package/dist/cjs/rules/no-nested-selectors/index.js +48 -36
  5. package/dist/cjs/rules/no-unsafe-selectors/index.js +88 -87
  6. package/dist/cjs/rules/no-unsafe-selectors/lint-selector.js +140 -101
  7. package/dist/cjs/rules/no-unsafe-selectors/walk-css-map.js +20 -50
  8. package/dist/cjs/rules/utils/create-rule-with-typed-config.js +29 -10
  9. package/dist/cjs/rules/utils/is-simple-selector.js +70 -0
  10. package/dist/cjs/rules/utils/parse-selector.js +30 -0
  11. package/dist/cjs/rules/utils/style-calls.js +127 -0
  12. package/dist/cjs/rules/utils/walk-style-call-properties.js +50 -0
  13. package/dist/es2019/rules/no-important-styles/index.js +79 -70
  14. package/dist/es2019/rules/no-nested-selectors/index.js +38 -36
  15. package/dist/es2019/rules/no-unsafe-selectors/index.js +68 -89
  16. package/dist/es2019/rules/no-unsafe-selectors/lint-selector.js +29 -23
  17. package/dist/es2019/rules/no-unsafe-selectors/walk-css-map.js +4 -30
  18. package/dist/es2019/rules/utils/create-rule-with-typed-config.js +30 -10
  19. package/dist/es2019/rules/utils/is-simple-selector.js +63 -0
  20. package/dist/es2019/rules/utils/parse-selector.js +23 -0
  21. package/dist/es2019/rules/utils/style-calls.js +89 -0
  22. package/dist/es2019/rules/utils/walk-style-call-properties.js +23 -0
  23. package/dist/esm/rules/no-important-styles/index.js +80 -100
  24. package/dist/esm/rules/no-nested-selectors/index.js +48 -34
  25. package/dist/esm/rules/no-unsafe-selectors/index.js +89 -87
  26. package/dist/esm/rules/no-unsafe-selectors/lint-selector.js +141 -102
  27. package/dist/esm/rules/no-unsafe-selectors/walk-css-map.js +19 -49
  28. package/dist/esm/rules/utils/create-rule-with-typed-config.js +30 -10
  29. package/dist/esm/rules/utils/is-simple-selector.js +64 -0
  30. package/dist/esm/rules/utils/parse-selector.js +23 -0
  31. package/dist/esm/rules/utils/style-calls.js +120 -0
  32. package/dist/esm/rules/utils/walk-style-call-properties.js +44 -0
  33. package/dist/types/rules/no-unsafe-selectors/constants.d.ts +1 -1
  34. package/dist/types/rules/no-unsafe-selectors/walk-css-map.d.ts +1 -7
  35. package/dist/types/rules/utils/create-rule-with-typed-config.d.ts +1 -1
  36. package/dist/types/rules/utils/is-simple-selector.d.ts +11 -0
  37. package/dist/types/rules/utils/parse-selector.d.ts +9 -0
  38. package/dist/types/rules/utils/style-calls.d.ts +17 -0
  39. package/dist/types/rules/utils/walk-style-call-properties.d.ts +5 -0
  40. package/package.json +3 -3
@@ -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
+ }
@@ -13,6 +13,6 @@ type HasAllUnique<Tuple, Union, Seen = never> = Tuple extends readonly [infer He
13
13
  * Exporting this so it isn't considered unused.
14
14
  */
15
15
  export type _ = Validate<HasAllUnique<typeof cssPseudos, CSSPseudos>>;
16
- 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", "&:popover-open", "&: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", "&::-webkit-details-marker", "&:active:visited", "&:focus:not(:focus-visible)", "&:focus::after", "&:focus::before", "&:focus-visible::after", "&:focus-visible::before", "&:focus-within::after", "&:focus-within::before", "&:hover::after", "&:hover::before", "&:visited:active", "&:visited:hover", "&:visited:focus", "&:visited:focus-visible", "&:visited:focus-within"];
16
+ 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', '&:popover-open', '&: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', '&::-webkit-details-marker', '&:active:visited', '&:focus:not(:focus-visible)', '&:focus::after', '&:focus::before', '&:focus-visible::after', '&:focus-visible::before', '&:focus-within::after', '&:focus-within::before', '&:hover::after', '&:hover::before', '&:visited:active', '&:visited:hover', '&:visited:focus', '&:visited:focus-visible', '&:visited:focus-within'];
17
17
  export declare const allowedPseudos: Set<string>;
18
18
  export {};
@@ -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 {};
@@ -14,5 +14,5 @@ export interface LintRuleMeta<Schema extends JSONSchema> extends Omit<BaseLintRu
14
14
  schema: Schema;
15
15
  }
16
16
  export declare const createLintRuleWithTypedConfig: <Schema extends JSONSchema & {
17
- type: "object";
17
+ type: 'object';
18
18
  }, Config = FromSchema<Schema>>(rule: LintRule<Schema, Config>) => Rule.RuleModule;
@@ -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 {};
@@ -0,0 +1,9 @@
1
+ import type { Rule } from 'eslint';
2
+ import cssSelectorParser from 'postcss-selector-parser';
3
+ declare const cssSelectorProcessor: ReturnType<typeof cssSelectorParser>;
4
+ type ParsedSelector = ReturnType<typeof cssSelectorProcessor.astSync>;
5
+ /**
6
+ * Parse each selector once per linted source file. Consumers treat the returned AST as read-only.
7
+ */
8
+ export declare function parseSelector(context: Rule.RuleContext, selectorText: string): ParsedSelector;
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.2",
3
+ "version": "2.1.4",
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",
@@ -28,8 +28,8 @@
28
28
  ],
29
29
  "atlaskit:src": "src/index.tsx",
30
30
  "dependencies": {
31
- "@atlaskit/eslint-plugin-design-system": "^16.2.0",
32
- "@atlaskit/eslint-utils": "^3.0.0",
31
+ "@atlaskit/eslint-plugin-design-system": "^16.11.0",
32
+ "@atlaskit/eslint-utils": "^3.1.0",
33
33
  "@babel/runtime": "^7.0.0",
34
34
  "@typescript-eslint/utils": "^7.1.0",
35
35
  "ajv": "^6.12.6",