eslint-plugin-no-re-export
Advanced tools
Comparing version
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var rules_1 = __importDefault(require("./rules")); | ||
const no_re_export_1 = require("./rules/no-re-export"); | ||
exports.default = { | ||
rules: rules_1.default, | ||
rules: { | ||
"no-re-export": no_re_export_1.default, | ||
}, | ||
}; | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var utils_1 = require("@typescript-eslint/utils"); | ||
var createRule = utils_1.ESLintUtils.RuleCreator(function (name) { | ||
return "https://github.com/christianvuerings/eslint-plugin-no-re-export/blob/main/docs/".concat(name, ".md"); | ||
}); | ||
const utils_1 = require("@typescript-eslint/utils"); | ||
const createRule = utils_1.ESLintUtils.RuleCreator((name) => `https://github.com/christianvuerings/eslint-plugin-no-re-export/blob/main/docs/${name}.md`); | ||
exports.default = createRule({ | ||
@@ -22,3 +11,3 @@ name: "no-re-export", | ||
description: "Disallow re-exports of imports. Avoids losing type safety & ensures bundle size does not increase by importing too much.", | ||
recommended: "recommended", | ||
recommended: "error", | ||
}, | ||
@@ -31,20 +20,20 @@ messages: { | ||
}, | ||
create: function (context) { | ||
var imports = new Map(); | ||
var exports = {}; | ||
var appendToExports = function (name, reportInfo) { | ||
exports[name] = __spreadArray(__spreadArray([], (exports[name] ? exports[name] : []), true), [reportInfo], false); | ||
create(context) { | ||
const imports = new Map(); | ||
const exports = {}; | ||
const appendToExports = (name, reportInfo) => { | ||
exports[name] = [...(exports[name] ? exports[name] : []), reportInfo]; | ||
}; | ||
return { | ||
ImportDefaultSpecifier: function (node) { | ||
imports.set(node.local.name, { node: node }); | ||
ImportDefaultSpecifier(node) { | ||
imports.set(node.local.name, { node }); | ||
}, | ||
ImportSpecifier: function (node) { | ||
imports.set(node.local.name, { node: node }); | ||
ImportSpecifier(node) { | ||
imports.set(node.local.name, { node }); | ||
}, | ||
ImportNamespaceSpecifier: function (node) { | ||
imports.set(node.local.name, { node: node }); | ||
ImportNamespaceSpecifier(node) { | ||
imports.set(node.local.name, { node }); | ||
}, | ||
// export * from 'app/CustomCustomButton' | ||
ExportAllDeclaration: function (node) { | ||
ExportAllDeclaration(node) { | ||
context.report({ | ||
@@ -58,10 +47,8 @@ loc: node.loc, | ||
}, | ||
ExportNamedDeclaration: function (node) { | ||
var _a; | ||
ExportNamedDeclaration(node) { | ||
if (node.declaration && | ||
((_a = node.declaration) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.VariableDeclaration && | ||
node.declaration?.type === utils_1.AST_NODE_TYPES.VariableDeclaration && | ||
node.declaration.declarations) { | ||
node.declaration.declarations.forEach(function (declaration) { | ||
var _a, _b, _c; | ||
if (((_a = declaration.init) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.Identifier && ((_b = declaration.init) === null || _b === void 0 ? void 0 : _b.name)) { | ||
node.declaration.declarations.forEach((declaration) => { | ||
if (declaration.init?.type === utils_1.AST_NODE_TYPES.Identifier && declaration.init?.name) { | ||
// export const CustomButtom = Button; | ||
@@ -73,9 +60,8 @@ appendToExports(declaration.init.name, { | ||
} | ||
else if (((_c = declaration.init) === null || _c === void 0 ? void 0 : _c.type) === utils_1.AST_NODE_TYPES.ObjectExpression && | ||
else if (declaration.init?.type === utils_1.AST_NODE_TYPES.ObjectExpression && | ||
declaration.init.properties) { | ||
declaration.init.properties.forEach(function (property) { | ||
var _a; | ||
if ((property === null || property === void 0 ? void 0 : property.type) === utils_1.AST_NODE_TYPES.Property && | ||
declaration.init.properties.forEach((property) => { | ||
if (property?.type === utils_1.AST_NODE_TYPES.Property && | ||
property.value.type === utils_1.AST_NODE_TYPES.Identifier && | ||
((_a = property.value) === null || _a === void 0 ? void 0 : _a.name)) { | ||
property.value?.name) { | ||
// export const CustomButton = { Button } | ||
@@ -92,3 +78,3 @@ appendToExports(property.value.name, { | ||
else if (node.specifiers) { | ||
node.specifiers.forEach(function (specifier) { | ||
node.specifiers.forEach((specifier) => { | ||
if (node.source && specifier.local.name === "default") { | ||
@@ -111,3 +97,3 @@ // export { default as Button } from 'app/CustomButtom'; | ||
}, | ||
ExportDefaultDeclaration: function (node) { | ||
ExportDefaultDeclaration(node) { | ||
if (node.declaration.type === utils_1.AST_NODE_TYPES.Identifier) { | ||
@@ -122,6 +108,5 @@ // export default Button | ||
"Program:exit": function programExit() { | ||
Object.keys(exports).forEach(function (exportName) { | ||
var reportInfoList = exports[exportName]; | ||
reportInfoList.forEach(function (_a) { | ||
var location = _a.location, type = _a.type; | ||
Object.keys(exports).forEach((exportName) => { | ||
const reportInfoList = exports[exportName]; | ||
reportInfoList.forEach(({ location, type }) => { | ||
if (imports.has(exportName) || type === "DefaultReExport") { | ||
@@ -128,0 +113,0 @@ context.report({ |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var rule_tester_1 = require("@typescript-eslint/rule-tester"); | ||
var no_re_export_1 = __importDefault(require("../rules/no-re-export")); | ||
var ruleTester = new rule_tester_1.RuleTester({ | ||
const utils_1 = require("@typescript-eslint/utils"); | ||
const no_re_export_1 = require("../rules/no-re-export"); | ||
const ruleTester = new utils_1.ESLintUtils.RuleTester({ | ||
parser: "@typescript-eslint/parser", | ||
@@ -13,39 +10,72 @@ }); | ||
valid: [ | ||
"\nimport Button from 'app/CustomButton';\nexport const CustomButtom = 'Button';\n", | ||
` | ||
import Button from 'app/CustomButton'; | ||
export const CustomButtom = 'Button'; | ||
`, | ||
], | ||
invalid: [ | ||
{ | ||
code: "\nimport Button1 from 'app/CustomButton';\nexport const CustomButtom = Button1;\n", | ||
code: ` | ||
import Button1 from 'app/CustomButton'; | ||
export const CustomButtom = Button1; | ||
`, | ||
errors: [{ messageId: "noReExports" }], | ||
}, | ||
{ | ||
code: "\nimport { Button as CustomButtom2 } from 'app/CustomButton';\nexport const CustomButtom = CustomButtom2;\n", | ||
code: ` | ||
import { Button as CustomButtom2 } from 'app/CustomButton'; | ||
export const CustomButtom = CustomButtom2; | ||
`, | ||
errors: [{ messageId: "noReExports" }], | ||
}, | ||
{ | ||
code: "\nimport * as Button3 from \"app/Button\"\nexport const CustomButtom = Button3;\n", | ||
code: ` | ||
import * as Button3 from "app/Button" | ||
export const CustomButtom = Button3; | ||
`, | ||
errors: [{ messageId: "noReExports" }], | ||
}, | ||
{ | ||
code: "\nimport Button4 from 'app/CustomButtom';\nexport default Button4;\n", | ||
code: ` | ||
import Button4 from 'app/CustomButtom'; | ||
export default Button4; | ||
`, | ||
errors: [{ messageId: "noReExports" }], | ||
}, | ||
{ | ||
code: "\nexport { default as Button5 } from 'app/CustomButtom';\n", | ||
code: ` | ||
export { default as Button5 } from 'app/CustomButtom'; | ||
`, | ||
errors: [{ messageId: "noReExports" }], | ||
}, | ||
{ | ||
code: "\nimport Button6 from 'app/CustomButtom';\nexport {\n Button6\n};\n", | ||
code: ` | ||
import Button6 from 'app/CustomButtom'; | ||
export { | ||
Button6 | ||
}; | ||
`, | ||
errors: [{ messageId: "noReExports" }], | ||
}, | ||
{ | ||
code: "\nimport Button7 from 'app/CustomButtom';\nexport const Buttons = {\n Button: Button7\n};\n", | ||
code: ` | ||
import Button7 from 'app/CustomButtom'; | ||
export const Buttons = { | ||
Button: Button7 | ||
}; | ||
`, | ||
errors: [{ messageId: "noReExports" }], | ||
}, | ||
{ | ||
code: "\nimport Button8 from 'app/CustomButtom';\nexport default Button8;\nexport { Button8 }\n", | ||
code: ` | ||
import Button8 from 'app/CustomButtom'; | ||
export default Button8; | ||
export { Button8 } | ||
`, | ||
errors: [{ messageId: "noReExports" }, { messageId: "noReExports" }], | ||
}, | ||
{ | ||
code: "\nexport * from 'app/CustomButtom';\n ", | ||
code: ` | ||
export * from 'app/CustomButtom'; | ||
`, | ||
errors: [{ messageId: "noReExports" }], | ||
@@ -52,0 +82,0 @@ }, |
{ | ||
"name": "eslint-plugin-no-re-export", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "ESLint plugin to disallow re-exporting in TypeScript/JavaScript", | ||
@@ -24,16 +24,8 @@ "main": "dist/index.js", | ||
], | ||
"exports": { | ||
".": { | ||
"types": "./index.d.ts", | ||
"default": "./dist/index.js" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"prepublishOnly": "npm run build", | ||
"dependencies": { | ||
"@typescript-eslint/utils": "^6.7.5" | ||
"@typescript-eslint/utils": "5.62.0" | ||
}, | ||
"devDependencies": { | ||
"@typescript-eslint/parser": "^6.7.5", | ||
"@typescript-eslint/rule-tester": "^6.7.5", | ||
"@typescript-eslint/parser": "5.62.0", | ||
"esbuild-jest": "^0.5.0", | ||
@@ -40,0 +32,0 @@ "eslint": "^8.51.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
5
-16.67%210
2.44%0
-100%16042
-11.45%9
-18.18%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed