@atlaskit/eslint-plugin-ui-styling-standard 0.14.0 → 0.14.2
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 +18 -0
- package/dist/cjs/rules/atlaskit-theme/index.js +10 -4
- package/dist/cjs/rules/no-important-styles/index.js +11 -17
- package/dist/cjs/rules/utils/create-rule-with-typed-config.js +60 -0
- package/dist/es2019/rules/atlaskit-theme/index.js +10 -4
- package/dist/es2019/rules/no-important-styles/index.js +13 -18
- package/dist/es2019/rules/utils/create-rule-with-typed-config.js +53 -0
- package/dist/esm/rules/atlaskit-theme/index.js +10 -4
- package/dist/esm/rules/no-important-styles/index.js +12 -18
- package/dist/esm/rules/utils/create-rule-with-typed-config.js +53 -0
- package/dist/types/rules/utils/create-rule-with-typed-config.d.ts +18 -0
- package/dist/types-ts4.5/rules/utils/create-rule-with-typed-config.d.ts +18 -0
- package/package.json +3 -2
- package/src/rules/atlaskit-theme/__tests__/test.ts +11 -0
- package/src/rules/atlaskit-theme/index.ts +10 -4
- package/src/rules/no-important-styles/__tests__/rule.test.tsx +12 -0
- package/src/rules/no-important-styles/index.tsx +11 -24
- package/src/rules/utils/create-rule-with-typed-config.tsx +87 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 0.14.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#101063](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/101063)
|
|
8
|
+
[`d135d014f1ae`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d135d014f1ae) -
|
|
9
|
+
The `atlaskit-theme` rule no longer reports on the `fontFallback` import from
|
|
10
|
+
`@atlaskit/theme/typography`
|
|
11
|
+
|
|
12
|
+
## 0.14.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#99639](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/99639)
|
|
17
|
+
[`e9887b5c7698`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e9887b5c7698) -
|
|
18
|
+
Internal refactoring of `no-important-styles` rule
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
|
|
3
21
|
## 0.14.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
|
@@ -72,8 +72,11 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
72
72
|
if (ancestors.some(function (ancestor) {
|
|
73
73
|
return ancestor.type === 'CallExpression' && ancestor.callee && (0, _isSupportedImport.isCompiled)(ancestor.callee, references, importSources);
|
|
74
74
|
})) {
|
|
75
|
-
//
|
|
76
|
-
|
|
75
|
+
// Ignore the fontFallback object as it contains strings to be used as token fallbacks
|
|
76
|
+
if ('name' in node && node.name !== 'fontFallback') {
|
|
77
|
+
// Check identifier for violations
|
|
78
|
+
checkIdentifier(node, context, references);
|
|
79
|
+
}
|
|
77
80
|
}
|
|
78
81
|
},
|
|
79
82
|
'TaggedTemplateExpression Identifier': function TaggedTemplateExpressionIdentifier(node) {
|
|
@@ -85,8 +88,11 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
85
88
|
if (ancestors.some(function (ancestor) {
|
|
86
89
|
return ancestor.type === 'TaggedTemplateExpression' && ancestor.tag && (0, _isSupportedImport.isCompiled)(ancestor.tag, references, importSources);
|
|
87
90
|
})) {
|
|
88
|
-
//
|
|
89
|
-
|
|
91
|
+
// Ignore the fontFallback object as it contains strings to be used as token fallbacks
|
|
92
|
+
if ('name' in node && node.name !== 'fontFallback') {
|
|
93
|
+
// Check identifier for violations
|
|
94
|
+
checkIdentifier(node, context, references);
|
|
95
|
+
}
|
|
90
96
|
}
|
|
91
97
|
}
|
|
92
98
|
};
|
|
@@ -6,24 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.rule = exports.default = void 0;
|
|
8
8
|
var _esquery = _interopRequireDefault(require("esquery"));
|
|
9
|
-
var _createRule = require("../utils/create-rule");
|
|
10
9
|
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
10
|
+
var _schema = require("@atlaskit/eslint-utils/schema");
|
|
11
|
+
var _createRuleWithTypedConfig = require("../utils/create-rule-with-typed-config");
|
|
11
12
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
12
13
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
14
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
|
-
var
|
|
15
|
-
type: 'object',
|
|
16
|
-
properties: {
|
|
17
|
-
importSources: {
|
|
18
|
-
type: 'array',
|
|
19
|
-
items: {
|
|
20
|
-
type: 'string'
|
|
21
|
-
},
|
|
22
|
-
uniqueItems: true
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}];
|
|
26
|
-
var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
15
|
+
var rule = exports.rule = (0, _createRuleWithTypedConfig.createLintRuleWithTypedConfig)({
|
|
27
16
|
meta: {
|
|
28
17
|
name: 'no-important-styles',
|
|
29
18
|
docs: {
|
|
@@ -35,10 +24,15 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
35
24
|
'no-important-styles': 'Important style declarations are disallowed. Refactor so the `!important` flag is not needed.'
|
|
36
25
|
},
|
|
37
26
|
type: 'problem',
|
|
38
|
-
schema:
|
|
27
|
+
schema: {
|
|
28
|
+
type: 'object',
|
|
29
|
+
properties: {
|
|
30
|
+
importSources: _schema.importSources
|
|
31
|
+
}
|
|
32
|
+
}
|
|
39
33
|
},
|
|
40
|
-
create: function create(context) {
|
|
41
|
-
var importSources =
|
|
34
|
+
create: function create(context, _ref) {
|
|
35
|
+
var importSources = _ref.importSources;
|
|
42
36
|
return {
|
|
43
37
|
CallExpression: function CallExpression(node) {
|
|
44
38
|
var _context$getScope = context.getScope(),
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createLintRuleWithTypedConfig = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _ajv = _interopRequireDefault(require("ajv"));
|
|
10
|
+
var _createRule = require("./create-rule");
|
|
11
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
|
+
var createLintRuleWithTypedConfig = exports.createLintRuleWithTypedConfig = function createLintRuleWithTypedConfig(rule) {
|
|
14
|
+
/**
|
|
15
|
+
* Gets the default config by running the same validator
|
|
16
|
+
* ESLint does against an empty config object with
|
|
17
|
+
* `useDefaults` option enabled.
|
|
18
|
+
*
|
|
19
|
+
* Any properties with a `default` property set in the schema
|
|
20
|
+
* will be populated with the specified default value.
|
|
21
|
+
*/
|
|
22
|
+
function getDefaultConfig() {
|
|
23
|
+
var ajv = new _ajv.default({
|
|
24
|
+
useDefaults: true
|
|
25
|
+
});
|
|
26
|
+
var validate = ajv.compile(rule.meta.schema);
|
|
27
|
+
var config = {};
|
|
28
|
+
/**
|
|
29
|
+
* The `validate()` function mutates the config object.
|
|
30
|
+
*/
|
|
31
|
+
validate(config);
|
|
32
|
+
return config;
|
|
33
|
+
}
|
|
34
|
+
return _objectSpread(_objectSpread({}, rule), {}, {
|
|
35
|
+
meta: _objectSpread(_objectSpread({}, rule.meta), {}, {
|
|
36
|
+
docs: _objectSpread(_objectSpread({}, rule.meta.docs), {}, {
|
|
37
|
+
url: (0, _createRule.getRuleUrl)(rule.meta.name)
|
|
38
|
+
}),
|
|
39
|
+
schema: [rule.meta.schema]
|
|
40
|
+
}),
|
|
41
|
+
create: function create(context) {
|
|
42
|
+
/**
|
|
43
|
+
* The config the user has passed.
|
|
44
|
+
*
|
|
45
|
+
* If they passed a config object, even if it is missing properties,
|
|
46
|
+
* ESLint will have added any default values defined using the
|
|
47
|
+
* `default` property in the schema.
|
|
48
|
+
*
|
|
49
|
+
* https://github.com/eslint/eslint/pull/11288
|
|
50
|
+
*/
|
|
51
|
+
var userConfig = context.options[0];
|
|
52
|
+
/**
|
|
53
|
+
* If the user passed no config object at all we need to obtain
|
|
54
|
+
* the default ourselves.
|
|
55
|
+
*/
|
|
56
|
+
var config = userConfig !== null && userConfig !== void 0 ? userConfig : getDefaultConfig();
|
|
57
|
+
return rule.create(context, config);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
};
|
|
@@ -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,19 +1,8 @@
|
|
|
1
1
|
import esquery from 'esquery';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
properties: {
|
|
7
|
-
importSources: {
|
|
8
|
-
type: 'array',
|
|
9
|
-
items: {
|
|
10
|
-
type: 'string'
|
|
11
|
-
},
|
|
12
|
-
uniqueItems: true
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}];
|
|
16
|
-
export const rule = createLintRule({
|
|
2
|
+
import { hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
3
|
+
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
4
|
+
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
5
|
+
export const rule = createLintRuleWithTypedConfig({
|
|
17
6
|
meta: {
|
|
18
7
|
name: 'no-important-styles',
|
|
19
8
|
docs: {
|
|
@@ -25,10 +14,16 @@ export const rule = createLintRule({
|
|
|
25
14
|
'no-important-styles': 'Important style declarations are disallowed. Refactor so the `!important` flag is not needed.'
|
|
26
15
|
},
|
|
27
16
|
type: 'problem',
|
|
28
|
-
schema
|
|
17
|
+
schema: {
|
|
18
|
+
type: 'object',
|
|
19
|
+
properties: {
|
|
20
|
+
importSources
|
|
21
|
+
}
|
|
22
|
+
}
|
|
29
23
|
},
|
|
30
|
-
create(context
|
|
31
|
-
|
|
24
|
+
create(context, {
|
|
25
|
+
importSources
|
|
26
|
+
}) {
|
|
32
27
|
return {
|
|
33
28
|
CallExpression(node) {
|
|
34
29
|
const {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import Ajv from 'ajv';
|
|
2
|
+
import { getRuleUrl } from './create-rule';
|
|
3
|
+
export const createLintRuleWithTypedConfig = rule => {
|
|
4
|
+
/**
|
|
5
|
+
* Gets the default config by running the same validator
|
|
6
|
+
* ESLint does against an empty config object with
|
|
7
|
+
* `useDefaults` option enabled.
|
|
8
|
+
*
|
|
9
|
+
* Any properties with a `default` property set in the schema
|
|
10
|
+
* will be populated with the specified default value.
|
|
11
|
+
*/
|
|
12
|
+
function getDefaultConfig() {
|
|
13
|
+
const ajv = new Ajv({
|
|
14
|
+
useDefaults: true
|
|
15
|
+
});
|
|
16
|
+
const validate = ajv.compile(rule.meta.schema);
|
|
17
|
+
const config = {};
|
|
18
|
+
/**
|
|
19
|
+
* The `validate()` function mutates the config object.
|
|
20
|
+
*/
|
|
21
|
+
validate(config);
|
|
22
|
+
return config;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
...rule,
|
|
26
|
+
meta: {
|
|
27
|
+
...rule.meta,
|
|
28
|
+
docs: {
|
|
29
|
+
...rule.meta.docs,
|
|
30
|
+
url: getRuleUrl(rule.meta.name)
|
|
31
|
+
},
|
|
32
|
+
schema: [rule.meta.schema]
|
|
33
|
+
},
|
|
34
|
+
create(context) {
|
|
35
|
+
/**
|
|
36
|
+
* The config the user has passed.
|
|
37
|
+
*
|
|
38
|
+
* If they passed a config object, even if it is missing properties,
|
|
39
|
+
* ESLint will have added any default values defined using the
|
|
40
|
+
* `default` property in the schema.
|
|
41
|
+
*
|
|
42
|
+
* https://github.com/eslint/eslint/pull/11288
|
|
43
|
+
*/
|
|
44
|
+
const userConfig = context.options[0];
|
|
45
|
+
/**
|
|
46
|
+
* If the user passed no config object at all we need to obtain
|
|
47
|
+
* the default ourselves.
|
|
48
|
+
*/
|
|
49
|
+
const config = userConfig !== null && userConfig !== void 0 ? userConfig : getDefaultConfig();
|
|
50
|
+
return rule.create(context, config);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
};
|
|
@@ -66,8 +66,11 @@ export var rule = createLintRule({
|
|
|
66
66
|
if (ancestors.some(function (ancestor) {
|
|
67
67
|
return ancestor.type === 'CallExpression' && ancestor.callee && isCompiled(ancestor.callee, references, importSources);
|
|
68
68
|
})) {
|
|
69
|
-
//
|
|
70
|
-
|
|
69
|
+
// Ignore the fontFallback object as it contains strings to be used as token fallbacks
|
|
70
|
+
if ('name' in node && node.name !== 'fontFallback') {
|
|
71
|
+
// Check identifier for violations
|
|
72
|
+
checkIdentifier(node, context, references);
|
|
73
|
+
}
|
|
71
74
|
}
|
|
72
75
|
},
|
|
73
76
|
'TaggedTemplateExpression Identifier': function TaggedTemplateExpressionIdentifier(node) {
|
|
@@ -79,8 +82,11 @@ export var rule = createLintRule({
|
|
|
79
82
|
if (ancestors.some(function (ancestor) {
|
|
80
83
|
return ancestor.type === 'TaggedTemplateExpression' && ancestor.tag && isCompiled(ancestor.tag, references, importSources);
|
|
81
84
|
})) {
|
|
82
|
-
//
|
|
83
|
-
|
|
85
|
+
// Ignore the fontFallback object as it contains strings to be used as token fallbacks
|
|
86
|
+
if ('name' in node && node.name !== 'fontFallback') {
|
|
87
|
+
// Check identifier for violations
|
|
88
|
+
checkIdentifier(node, context, references);
|
|
89
|
+
}
|
|
84
90
|
}
|
|
85
91
|
}
|
|
86
92
|
};
|
|
@@ -2,21 +2,10 @@ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol
|
|
|
2
2
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
3
3
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
4
4
|
import esquery from 'esquery';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
properties: {
|
|
10
|
-
importSources: {
|
|
11
|
-
type: 'array',
|
|
12
|
-
items: {
|
|
13
|
-
type: 'string'
|
|
14
|
-
},
|
|
15
|
-
uniqueItems: true
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}];
|
|
19
|
-
export var rule = createLintRule({
|
|
5
|
+
import { hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
6
|
+
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
7
|
+
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
8
|
+
export var rule = createLintRuleWithTypedConfig({
|
|
20
9
|
meta: {
|
|
21
10
|
name: 'no-important-styles',
|
|
22
11
|
docs: {
|
|
@@ -28,10 +17,15 @@ export var rule = createLintRule({
|
|
|
28
17
|
'no-important-styles': 'Important style declarations are disallowed. Refactor so the `!important` flag is not needed.'
|
|
29
18
|
},
|
|
30
19
|
type: 'problem',
|
|
31
|
-
schema:
|
|
20
|
+
schema: {
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: {
|
|
23
|
+
importSources: importSources
|
|
24
|
+
}
|
|
25
|
+
}
|
|
32
26
|
},
|
|
33
|
-
create: function create(context) {
|
|
34
|
-
var importSources =
|
|
27
|
+
create: function create(context, _ref) {
|
|
28
|
+
var importSources = _ref.importSources;
|
|
35
29
|
return {
|
|
36
30
|
CallExpression: function CallExpression(node) {
|
|
37
31
|
var _context$getScope = context.getScope(),
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
import Ajv from 'ajv';
|
|
5
|
+
import { getRuleUrl } from './create-rule';
|
|
6
|
+
export var createLintRuleWithTypedConfig = function createLintRuleWithTypedConfig(rule) {
|
|
7
|
+
/**
|
|
8
|
+
* Gets the default config by running the same validator
|
|
9
|
+
* ESLint does against an empty config object with
|
|
10
|
+
* `useDefaults` option enabled.
|
|
11
|
+
*
|
|
12
|
+
* Any properties with a `default` property set in the schema
|
|
13
|
+
* will be populated with the specified default value.
|
|
14
|
+
*/
|
|
15
|
+
function getDefaultConfig() {
|
|
16
|
+
var ajv = new Ajv({
|
|
17
|
+
useDefaults: true
|
|
18
|
+
});
|
|
19
|
+
var validate = ajv.compile(rule.meta.schema);
|
|
20
|
+
var config = {};
|
|
21
|
+
/**
|
|
22
|
+
* The `validate()` function mutates the config object.
|
|
23
|
+
*/
|
|
24
|
+
validate(config);
|
|
25
|
+
return config;
|
|
26
|
+
}
|
|
27
|
+
return _objectSpread(_objectSpread({}, rule), {}, {
|
|
28
|
+
meta: _objectSpread(_objectSpread({}, rule.meta), {}, {
|
|
29
|
+
docs: _objectSpread(_objectSpread({}, rule.meta.docs), {}, {
|
|
30
|
+
url: getRuleUrl(rule.meta.name)
|
|
31
|
+
}),
|
|
32
|
+
schema: [rule.meta.schema]
|
|
33
|
+
}),
|
|
34
|
+
create: function create(context) {
|
|
35
|
+
/**
|
|
36
|
+
* The config the user has passed.
|
|
37
|
+
*
|
|
38
|
+
* If they passed a config object, even if it is missing properties,
|
|
39
|
+
* ESLint will have added any default values defined using the
|
|
40
|
+
* `default` property in the schema.
|
|
41
|
+
*
|
|
42
|
+
* https://github.com/eslint/eslint/pull/11288
|
|
43
|
+
*/
|
|
44
|
+
var userConfig = context.options[0];
|
|
45
|
+
/**
|
|
46
|
+
* If the user passed no config object at all we need to obtain
|
|
47
|
+
* the default ourselves.
|
|
48
|
+
*/
|
|
49
|
+
var config = userConfig !== null && userConfig !== void 0 ? userConfig : getDefaultConfig();
|
|
50
|
+
return rule.create(context, config);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import type { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
3
|
+
import type { LintRule as BaseLintRule, LintRuleMeta as BaseLintRuleMeta } from '@atlaskit/eslint-utils/create-rule';
|
|
4
|
+
export interface LintRule<Schema extends JSONSchema, Config> extends Omit<BaseLintRule, 'meta' | 'create'> {
|
|
5
|
+
meta: LintRuleMeta<Schema>;
|
|
6
|
+
create(context: Rule.RuleContext, config: Config): Rule.RuleListener;
|
|
7
|
+
/**
|
|
8
|
+
* Unsure why the eslint typings include this when the docs
|
|
9
|
+
* say the schema should be in meta.
|
|
10
|
+
*/
|
|
11
|
+
schema?: never;
|
|
12
|
+
}
|
|
13
|
+
export interface LintRuleMeta<Schema extends JSONSchema> extends Omit<BaseLintRuleMeta, 'schema'> {
|
|
14
|
+
schema: Schema;
|
|
15
|
+
}
|
|
16
|
+
export declare const createLintRuleWithTypedConfig: <Schema extends JSONSchema & {
|
|
17
|
+
type: 'object';
|
|
18
|
+
}, Config = FromSchema<Schema>>(rule: LintRule<Schema, Config>) => Rule.RuleModule;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import type { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
3
|
+
import type { LintRule as BaseLintRule, LintRuleMeta as BaseLintRuleMeta } from '@atlaskit/eslint-utils/create-rule';
|
|
4
|
+
export interface LintRule<Schema extends JSONSchema, Config> extends Omit<BaseLintRule, 'meta' | 'create'> {
|
|
5
|
+
meta: LintRuleMeta<Schema>;
|
|
6
|
+
create(context: Rule.RuleContext, config: Config): Rule.RuleListener;
|
|
7
|
+
/**
|
|
8
|
+
* Unsure why the eslint typings include this when the docs
|
|
9
|
+
* say the schema should be in meta.
|
|
10
|
+
*/
|
|
11
|
+
schema?: never;
|
|
12
|
+
}
|
|
13
|
+
export interface LintRuleMeta<Schema extends JSONSchema> extends Omit<BaseLintRuleMeta, 'schema'> {
|
|
14
|
+
schema: Schema;
|
|
15
|
+
}
|
|
16
|
+
export declare const createLintRuleWithTypedConfig: <Schema extends JSONSchema & {
|
|
17
|
+
type: 'object';
|
|
18
|
+
}, Config = FromSchema<Schema>>(rule: LintRule<Schema, Config>) => Rule.RuleModule;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-ui-styling-standard",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.2",
|
|
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",
|
|
@@ -39,9 +39,10 @@
|
|
|
39
39
|
".": "./src/index.tsx"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@atlaskit/eslint-utils": "^1.
|
|
42
|
+
"@atlaskit/eslint-utils": "^1.4.0",
|
|
43
43
|
"@babel/runtime": "^7.0.0",
|
|
44
44
|
"@typescript-eslint/utils": "^5.48.1",
|
|
45
|
+
"ajv": "^6.12.6",
|
|
45
46
|
"eslint-codemod-utils": "^1.8.6",
|
|
46
47
|
"eslint-scope": "^8.0.0",
|
|
47
48
|
"esquery": "^1.5.0",
|
|
@@ -13,6 +13,17 @@ const valid = [
|
|
|
13
13
|
\`;
|
|
14
14
|
`,
|
|
15
15
|
},
|
|
16
|
+
{
|
|
17
|
+
name: 'Valid typography use in compiled (fontFallback)',
|
|
18
|
+
code: outdent`
|
|
19
|
+
import { styled } from '@compiled/react';
|
|
20
|
+
import { fontFallback } from '@atlaskit/theme/typography';
|
|
21
|
+
import { token } from '@atlaskit/tokens';
|
|
22
|
+
export const HeadingComponent = styled.h2\`
|
|
23
|
+
font: \${token('font.body', fontFallback.body.medium)}
|
|
24
|
+
\`;
|
|
25
|
+
`,
|
|
26
|
+
},
|
|
16
27
|
{
|
|
17
28
|
name: 'Valid elevation use in styled-components',
|
|
18
29
|
code: outdent`
|
|
@@ -107,8 +107,11 @@ export const rule = createLintRule({
|
|
|
107
107
|
isCompiled(ancestor.callee, references, importSources),
|
|
108
108
|
)
|
|
109
109
|
) {
|
|
110
|
-
//
|
|
111
|
-
|
|
110
|
+
// Ignore the fontFallback object as it contains strings to be used as token fallbacks
|
|
111
|
+
if ('name' in node && node.name !== 'fontFallback') {
|
|
112
|
+
// Check identifier for violations
|
|
113
|
+
checkIdentifier(node, context, references);
|
|
114
|
+
}
|
|
112
115
|
}
|
|
113
116
|
},
|
|
114
117
|
|
|
@@ -125,8 +128,11 @@ export const rule = createLintRule({
|
|
|
125
128
|
isCompiled(ancestor.tag, references, importSources),
|
|
126
129
|
)
|
|
127
130
|
) {
|
|
128
|
-
//
|
|
129
|
-
|
|
131
|
+
// Ignore the fontFallback object as it contains strings to be used as token fallbacks
|
|
132
|
+
if ('name' in node && node.name !== 'fontFallback') {
|
|
133
|
+
// Check identifier for violations
|
|
134
|
+
checkIdentifier(node, context, references);
|
|
135
|
+
}
|
|
130
136
|
}
|
|
131
137
|
},
|
|
132
138
|
};
|
|
@@ -149,5 +149,17 @@ tester.run('no-important-styles', rule, {
|
|
|
149
149
|
`,
|
|
150
150
|
errors: [{ messageId: 'no-important-styles' }],
|
|
151
151
|
},
|
|
152
|
+
{
|
|
153
|
+
name: 'uses default when options object is provided without importSources',
|
|
154
|
+
code: `
|
|
155
|
+
import { css } from '@compiled/react';
|
|
156
|
+
|
|
157
|
+
const styles = css({
|
|
158
|
+
color: 'red !important'
|
|
159
|
+
});
|
|
160
|
+
`,
|
|
161
|
+
errors: [{ messageId: 'no-important-styles' }],
|
|
162
|
+
options: [{}],
|
|
163
|
+
},
|
|
152
164
|
],
|
|
153
165
|
});
|
|
@@ -2,27 +2,11 @@ import esquery from 'esquery';
|
|
|
2
2
|
|
|
3
3
|
import type { Property } from 'estree';
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
hasStyleObjectArguments,
|
|
9
|
-
} from '@atlaskit/eslint-utils/is-supported-import';
|
|
10
|
-
import type { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
|
|
5
|
+
import { hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
6
|
+
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
7
|
+
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
11
8
|
|
|
12
|
-
const
|
|
13
|
-
{
|
|
14
|
-
type: 'object',
|
|
15
|
-
properties: {
|
|
16
|
-
importSources: {
|
|
17
|
-
type: 'array',
|
|
18
|
-
items: { type: 'string' },
|
|
19
|
-
uniqueItems: true,
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
];
|
|
24
|
-
|
|
25
|
-
export const rule = createLintRule({
|
|
9
|
+
export const rule = createLintRuleWithTypedConfig({
|
|
26
10
|
meta: {
|
|
27
11
|
name: 'no-important-styles',
|
|
28
12
|
docs: {
|
|
@@ -35,11 +19,14 @@ export const rule = createLintRule({
|
|
|
35
19
|
'Important style declarations are disallowed. Refactor so the `!important` flag is not needed.',
|
|
36
20
|
},
|
|
37
21
|
type: 'problem',
|
|
38
|
-
schema
|
|
22
|
+
schema: {
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
importSources,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
39
28
|
},
|
|
40
|
-
create(context) {
|
|
41
|
-
const importSources = getImportSources(context);
|
|
42
|
-
|
|
29
|
+
create(context, { importSources }) {
|
|
43
30
|
return {
|
|
44
31
|
CallExpression(node) {
|
|
45
32
|
const { references } = context.getScope();
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import Ajv from 'ajv';
|
|
2
|
+
import type { Rule } from 'eslint';
|
|
3
|
+
import type { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
LintRule as BaseLintRule,
|
|
7
|
+
LintRuleMeta as BaseLintRuleMeta,
|
|
8
|
+
} from '@atlaskit/eslint-utils/create-rule';
|
|
9
|
+
|
|
10
|
+
import { getRuleUrl } from './create-rule';
|
|
11
|
+
|
|
12
|
+
export interface LintRule<Schema extends JSONSchema, Config>
|
|
13
|
+
extends Omit<BaseLintRule, 'meta' | 'create'> {
|
|
14
|
+
meta: LintRuleMeta<Schema>;
|
|
15
|
+
|
|
16
|
+
create(context: Rule.RuleContext, config: Config): Rule.RuleListener;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Unsure why the eslint typings include this when the docs
|
|
20
|
+
* say the schema should be in meta.
|
|
21
|
+
*/
|
|
22
|
+
schema?: never;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface LintRuleMeta<Schema extends JSONSchema>
|
|
26
|
+
extends Omit<BaseLintRuleMeta, 'schema'> {
|
|
27
|
+
schema: Schema;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const createLintRuleWithTypedConfig = <
|
|
31
|
+
Schema extends JSONSchema & { type: 'object' },
|
|
32
|
+
Config = FromSchema<Schema>,
|
|
33
|
+
>(
|
|
34
|
+
rule: LintRule<Schema, Config>,
|
|
35
|
+
) => {
|
|
36
|
+
/**
|
|
37
|
+
* Gets the default config by running the same validator
|
|
38
|
+
* ESLint does against an empty config object with
|
|
39
|
+
* `useDefaults` option enabled.
|
|
40
|
+
*
|
|
41
|
+
* Any properties with a `default` property set in the schema
|
|
42
|
+
* will be populated with the specified default value.
|
|
43
|
+
*/
|
|
44
|
+
function getDefaultConfig(): Config {
|
|
45
|
+
const ajv = new Ajv({ useDefaults: true });
|
|
46
|
+
const validate = ajv.compile(rule.meta.schema);
|
|
47
|
+
|
|
48
|
+
const config = {};
|
|
49
|
+
/**
|
|
50
|
+
* The `validate()` function mutates the config object.
|
|
51
|
+
*/
|
|
52
|
+
validate(config);
|
|
53
|
+
|
|
54
|
+
return config as Config;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
...rule,
|
|
59
|
+
meta: {
|
|
60
|
+
...rule.meta,
|
|
61
|
+
docs: {
|
|
62
|
+
...rule.meta.docs,
|
|
63
|
+
url: getRuleUrl(rule.meta.name),
|
|
64
|
+
},
|
|
65
|
+
schema: [rule.meta.schema],
|
|
66
|
+
},
|
|
67
|
+
create(context) {
|
|
68
|
+
/**
|
|
69
|
+
* The config the user has passed.
|
|
70
|
+
*
|
|
71
|
+
* If they passed a config object, even if it is missing properties,
|
|
72
|
+
* ESLint will have added any default values defined using the
|
|
73
|
+
* `default` property in the schema.
|
|
74
|
+
*
|
|
75
|
+
* https://github.com/eslint/eslint/pull/11288
|
|
76
|
+
*/
|
|
77
|
+
const userConfig = context.options[0] as Config | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* If the user passed no config object at all we need to obtain
|
|
80
|
+
* the default ourselves.
|
|
81
|
+
*/
|
|
82
|
+
const config = userConfig ?? getDefaultConfig();
|
|
83
|
+
|
|
84
|
+
return rule.create(context, config);
|
|
85
|
+
},
|
|
86
|
+
} as Rule.RuleModule;
|
|
87
|
+
};
|