Skip to content

Commit

Permalink
Fixed ESLint rule that prevents cross-component imports (#1050)
Browse files Browse the repository at this point in the history
* Update eslint-plugin-import

* Prevent components from importing from other components, but allow self-imports

* Add comment explaining what the glob mapping is for
  • Loading branch information
carterworks authored Oct 24, 2023
1 parent c799bfd commit fe0da27
Show file tree
Hide file tree
Showing 3 changed files with 1,076 additions and 402 deletions.
42 changes: 20 additions & 22 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
const glob = require("glob");

const allComponentPaths = glob.sync("src/components/*/");

module.exports = {
extends: ["airbnb-base", "prettier", "plugin:testcafe/recommended"],
env: {
Expand Down Expand Up @@ -45,33 +49,27 @@ module.exports = {
"error",
{
zones: [
// prevent components from importing from other components, but allow
// importing from themselves
...allComponentPaths.map((path, index, allPaths) => ({
target: path,
from: [
"src/core",
"src/baseCode",
...allPaths.filter(p => p !== path)
]
})),
{
from: "./src/components",
target: "./src/core"
},
{
from: "./src/core",
target: "./src/components"
},
{
from: "./src/core",
target: "./src/utils"
},
{
from: "./src/core",
target: "./src/constants"
},
{
from: "./src/components",
target: "./src/utils"
target: "src/core",
from: "src/baseCode"
},
{
from: "./src/components",
target: "./src/constants"
target: "src/utils",
from: ["src/core", "src/components", "src/baseCode"]
},
{
from: "./src/utils",
target: "./src/constants"
target: "src/constants",
from: ["src/core", "src/components", "src/utils", "src/baseCode"]
}
]
}
Expand Down
Loading

0 comments on commit fe0da27

Please sign in to comment.