@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
107 lines (105 loc) • 3.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.name = exports.default = void 0;
var _createLintRule = require("../utils/create-lint-rule");
var _errorBoundary = require("../utils/error-boundary");
var _checks = require("./checks");
/**
* Forked from original `no-restricted-imports` although the source has been substantially changed.
*
* To ensure compliance the license from eslint has been included and the original attribution.
* @author Guy Ellis
*
* Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
var name = exports.name = 'no-deprecated-imports';
var rule = (0, _createLintRule.createLintRule)({
meta: {
name: name,
fixable: 'code',
hasSuggestions: true,
type: 'suggestion',
docs: {
description: 'Disallow importing deprecated modules.',
recommended: true,
severity: 'error'
},
messages: {
pathWithCustomMessage: "'{{importSource}}' import is restricted from being used. {{customMessage}}",
importNameWithCustomMessage: "'{{importName}}' import from '{{importSource}}' is restricted. {{customMessage}}"
},
schema: [{
type: 'object',
properties: {
turnOffAutoFixer: {
type: 'boolean'
},
deprecatedConfig: {
type: 'object',
properties: {
'.+': {
type: 'object',
properties: {
message: {
type: 'string'
},
importSpecifiers: {
type: 'array',
items: {
type: 'object',
properties: {
importName: {
type: 'string'
},
message: {
type: 'string'
}
},
required: ['importName']
}
}
}
}
}
}
},
additionalProperties: false
}]
},
create: function create(context) {
var _createChecks = (0, _checks.createChecks)(context),
checkImportNode = _createChecks.checkImportNode,
checkExportNode = _createChecks.checkExportNode,
checkJSXElement = _createChecks.checkJSXElement,
checkIdentifier = _createChecks.checkIdentifier,
throwErrors = _createChecks.throwErrors;
return (0, _errorBoundary.errorBoundary)({
ImportDeclaration: checkImportNode,
ExportNamedDeclaration: checkExportNode,
JSXElement: checkJSXElement,
Identifier: checkIdentifier,
'Program:exit': throwErrors
});
}
});
var _default = exports.default = rule;