@atlaskit/eslint-plugin-ui-styling-standard
Version:
The eslint plugin to enforce and educate on Atlassian's UI Styling Standard
86 lines (85 loc) • 2.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
var _createRule = require("../utils/create-rule");
var _messages = require("./messages");
var _utils = require("./utils");
var schema = [{
type: 'object',
additionalProperties: false,
properties: {
importSources: {
type: 'array',
items: {
type: 'string'
},
uniqueItems: true
},
allowedFunctionCalls: {
type: 'array',
items: {
type: 'array',
minItems: 2,
maxItems: 2,
items: [{
type: 'string'
}, {
type: 'string'
}]
},
uniqueItems: true
},
allowedDynamicKeys: {
type: 'array',
items: {
type: 'array',
minItems: 2,
maxItems: 2,
items: [{
type: 'string'
}, {
type: 'string'
}]
},
uniqueItems: true
}
}
}];
var rule = (0, _createRule.createLintRule)({
meta: {
name: 'no-unsafe-values',
docs: {
description: 'Disallows styles that are difficult/impossible to statically anaylze.',
recommended: true,
severity: 'error'
},
messages: _messages.messages,
type: 'problem',
schema: schema
},
create: function create(context) {
var importSources = (0, _isSupportedImport.getImportSources)(context);
return {
CallExpression: function CallExpression(node) {
var _getScope = (0, _contextCompat.getScope)(context, node),
references = _getScope.references;
if (!(0, _isSupportedImport.isCss)(node.callee, references, importSources) && !(0, _isSupportedImport.isStyled)(node.callee, references, importSources) && !(0, _isSupportedImport.isKeyframes)(node.callee, references, importSources) && !(0, _isSupportedImport.isCssMap)(node.callee, references, importSources) && !(0, _isSupportedImport.isXcss)(node.callee, references, importSources)) {
return;
}
if ((0, _isSupportedImport.isStyled)(node.callee, references, importSources) && (node.parent.type === 'CallExpression' || node.parent.type === 'TaggedTemplateExpression')) {
/**
* If it is of the form styled(Base)({}) we don't want to lint the inner function arguments.
*/
return;
}
var linter = new _utils.Linter(context, node);
linter.run();
}
};
}
});
var _default = exports.default = rule;