Path: blob/main/tests/src/rules/no-internal-modules.js
829 views
import { RuleTester } from 'eslint';1import flatMap from 'array.prototype.flatmap';2import rule from 'rules/no-internal-modules';34import { test, testFilePath, getTSParsers } from '../utils';56const ruleTester = new RuleTester();78ruleTester.run('no-internal-modules', rule, {9valid: [10// imports11test({12code: 'import a from "./plugin2"',13filename: testFilePath('./internal-modules/plugins/plugin.js'),14options: [],15}),16test({17code: 'const a = require("./plugin2")',18filename: testFilePath('./internal-modules/plugins/plugin.js'),19}),20test({21code: 'const a = require("./plugin2/")',22filename: testFilePath('./internal-modules/plugins/plugin.js'),23}),24test({25code: 'const dynamic = "./plugin2/"; const a = require(dynamic)',26filename: testFilePath('./internal-modules/plugins/plugin.js'),27}),28test({29code: 'import b from "./internal.js"',30filename: testFilePath('./internal-modules/plugins/plugin2/index.js'),31}),32test({33code: 'import get from "lodash.get"',34filename: testFilePath('./internal-modules/plugins/plugin2/index.js'),35}),36test({37code: 'import b from "@org/package"',38filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),39}),40test({41code: 'import b from "../../api/service"',42filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),43options: [ {44allow: [ '**/api/*' ],45} ],46}),47test({48code: 'import "jquery/dist/jquery"',49filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),50options: [ {51allow: [ 'jquery/dist/*' ],52} ],53}),54test({55code: 'import "./app/index.js";\nimport "./app/index"',56filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),57options: [ {58allow: [ '**/index{.js,}' ],59} ],60}),61test({62code: 'import a from "./plugin2/thing"',63filename: testFilePath('./internal-modules/plugins/plugin.js'),64options: [ {65forbid: [ '**/api/*' ],66} ],67}),68test({69code: 'const a = require("./plugin2/thing")',70filename: testFilePath('./internal-modules/plugins/plugin.js'),71options: [ {72forbid: [ '**/api/*' ],73} ],74}),75test({76code: 'import b from "app/a"',77filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),78options: [ {79forbid: [ 'app/**/**' ],80} ],81}),82test({83code: 'import b from "@org/package"',84filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),85options: [ {86forbid: [ '@org/package/*' ],87} ],88}),89// exports90test({91code: 'export {a} from "./internal.js"',92filename: testFilePath('./internal-modules/plugins/plugin2/index.js'),93}),94test({95code: 'export * from "lodash.get"',96filename: testFilePath('./internal-modules/plugins/plugin2/index.js'),97}),98test({99code: 'export {b} from "@org/package"',100filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),101}),102test({103code: 'export {b} from "../../api/service"',104filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),105options: [ {106allow: [ '**/api/*' ],107} ],108}),109test({110code: 'export * from "jquery/dist/jquery"',111filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),112options: [ {113allow: [ 'jquery/dist/*' ],114} ],115}),116test({117code: 'export * from "./app/index.js";\nexport * from "./app/index"',118filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),119options: [ {120allow: [ '**/index{.js,}' ],121} ],122}),123test({124code: `125export class AuthHelper {126127static checkAuth(auth) {128}129}130`,131}),132...flatMap(getTSParsers(), (parser) => [133test({134code: `135export class AuthHelper {136137public static checkAuth(auth?: string): boolean {138}139}140`,141parser,142}),143]),144test({145code: 'export * from "./plugin2/thing"',146filename: testFilePath('./internal-modules/plugins/plugin.js'),147options: [ {148forbid: [ '**/api/*' ],149} ],150}),151test({152code: 'export * from "app/a"',153filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),154options: [ {155forbid: [ 'app/**/**' ],156} ],157}),158test({159code: 'export { b } from "@org/package"',160filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),161options: [ {162forbid: [ '@org/package/*' ],163} ],164}),165test({166code: 'export * from "./app/index.js";\nexport * from "./app/index"',167filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),168options: [ {169forbid: [ '**/index.ts' ],170} ],171}),172],173174invalid: [175// imports176test({177code: 'import "./plugin2/index.js";\nimport "./plugin2/app/index"',178filename: testFilePath('./internal-modules/plugins/plugin.js'),179options: [ {180allow: [ '*/index.js' ],181} ],182errors: [ {183message: 'Reaching to "./plugin2/app/index" is not allowed.',184line: 2,185column: 8,186} ],187}),188test({189code: 'import "./app/index.js"',190filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),191errors: [ {192message: 'Reaching to "./app/index.js" is not allowed.',193line: 1,194column: 8,195} ],196}),197test({198code: 'import b from "./plugin2/internal"',199filename: testFilePath('./internal-modules/plugins/plugin.js'),200errors: [ {201message: 'Reaching to "./plugin2/internal" is not allowed.',202line: 1,203column: 15,204} ],205}),206test({207code: 'import a from "../api/service/index"',208filename: testFilePath('./internal-modules/plugins/plugin.js'),209options: [ {210allow: [ '**/internal-modules/*' ],211} ],212errors: [213{214message: 'Reaching to "../api/service/index" is not allowed.',215line: 1,216column: 15,217},218],219}),220test({221code: 'import b from "@org/package/internal"',222filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),223errors: [224{225message: 'Reaching to "@org/package/internal" is not allowed.',226line: 1,227column: 15,228},229],230}),231test({232code: 'import get from "debug/node"',233filename: testFilePath('./internal-modules/plugins/plugin.js'),234errors: [235{236message: 'Reaching to "debug/node" is not allowed.',237line: 1,238column: 17,239},240],241}),242test({243code: 'import "./app/index.js"',244filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),245options: [ {246forbid: [ '*/app/*' ],247} ],248errors: [ {249message: 'Reaching to "./app/index.js" is not allowed.',250line: 1,251column: 8,252} ],253}),254test({255code: 'import b from "@org/package"',256filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),257options: [ {258forbid: [ '@org/**' ],259} ],260errors: [ {261message: 'Reaching to "@org/package" is not allowed.',262line: 1,263column: 15,264} ],265}),266test({267code: 'import b from "app/a/b"',268filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),269options: [ {270forbid: [ 'app/**/**' ],271} ],272errors: [ {273message: 'Reaching to "app/a/b" is not allowed.',274line: 1,275column: 15,276} ],277}),278test({279code: 'import get from "lodash.get"',280filename: testFilePath('./internal-modules/plugins/plugin2/index.js'),281options: [ {282forbid: [ 'lodash.*' ],283} ],284errors: [ {285message: 'Reaching to "lodash.get" is not allowed.',286line: 1,287column: 17,288} ],289}),290test({291code: 'import "./app/index.js";\nimport "./app/index"',292filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),293options: [ {294forbid: [ '**/index{.js,}' ],295} ],296errors: [ {297message: 'Reaching to "./app/index.js" is not allowed.',298line: 1,299column: 8,300}, {301message: 'Reaching to "./app/index" is not allowed.',302line: 2,303column: 8,304} ],305}),306// exports307test({308code: 'export * from "./plugin2/index.js";\nexport * from "./plugin2/app/index"',309filename: testFilePath('./internal-modules/plugins/plugin.js'),310options: [ {311allow: [ '*/index.js' ],312} ],313errors: [ {314message: 'Reaching to "./plugin2/app/index" is not allowed.',315line: 2,316column: 15,317} ],318}),319test({320code: 'export * from "./app/index.js"',321filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),322errors: [ {323message: 'Reaching to "./app/index.js" is not allowed.',324line: 1,325column: 15,326} ],327}),328test({329code: 'export {b} from "./plugin2/internal"',330filename: testFilePath('./internal-modules/plugins/plugin.js'),331errors: [ {332message: 'Reaching to "./plugin2/internal" is not allowed.',333line: 1,334column: 17,335} ],336}),337test({338code: 'export {a} from "../api/service/index"',339filename: testFilePath('./internal-modules/plugins/plugin.js'),340options: [ {341allow: [ '**/internal-modules/*' ],342} ],343errors: [344{345message: 'Reaching to "../api/service/index" is not allowed.',346line: 1,347column: 17,348},349],350}),351test({352code: 'export {b} from "@org/package/internal"',353filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),354errors: [355{356message: 'Reaching to "@org/package/internal" is not allowed.',357line: 1,358column: 17,359},360],361}),362test({363code: 'export {get} from "debug/node"',364filename: testFilePath('./internal-modules/plugins/plugin.js'),365errors: [366{367message: 'Reaching to "debug/node" is not allowed.',368line: 1,369column: 19,370},371],372}),373test({374code: 'export * from "./plugin2/thing"',375filename: testFilePath('./internal-modules/plugins/plugin.js'),376options: [ {377forbid: [ '**/plugin2/*' ],378} ],379errors: [380{381message: 'Reaching to "./plugin2/thing" is not allowed.',382line: 1,383column: 15,384},385],386}),387test({388code: 'export * from "app/a"',389filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),390options: [ {391forbid: [ '**' ],392} ],393errors: [394{395message: 'Reaching to "app/a" is not allowed.',396line: 1,397column: 15,398},399],400}),401],402});403404405