Skip to content

Commit

Permalink
Merge pull request #344 from javierbrea/release
Browse files Browse the repository at this point in the history
Release v5.0.1
  • Loading branch information
javierbrea authored Nov 11, 2024
2 parents bd0a993 + c8cb201 commit 0779f76
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
### Removed
### BREAKING CHANGES

## [5.0.1] - 2024-11-11

- fix([#340](https://github.com/javierbrea/eslint-plugin-boundaries/issues/340)): Fix bug producing that target option had captured values from the target dependency when templating `${from}` property ([@DeyLak](https://github.com/DeyLak))

## [5.0.0] - 2024-11-05

### Changed
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-boundaries",
"version": "5.0.0",
"version": "5.0.1",
"description": "Eslint plugin checking architecture boundaries between elements",
"keywords": [
"eslint",
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sonar.organization=javierbrea
sonar.projectKey=javierbrea_eslint-plugin-boundaries
sonar.projectVersion=5.0.0
sonar.projectVersion=5.0.1

sonar.javascript.file.suffixes=.js
sonar.sourceEncoding=UTF-8
Expand Down
8 changes: 5 additions & 3 deletions src/helpers/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function isMatchElementType(
return isMatchElementKey(elementInfo, matcher, options, "type", elementsToCompareCapturedValues);
}

function getElementRules(elementInfo, options, mainKey) {
function getElementRules(targetElement, options, mainKey, fromElement) {
if (!options.rules) {
return [];
}
Expand All @@ -150,7 +150,7 @@ function getElementRules(elementInfo, options, mainKey) {
};
})
.filter((rule) => {
return ruleMatch(rule[key], elementInfo, isMatchElementType, elementInfo).result;
return ruleMatch(rule[key], targetElement, isMatchElementType, fromElement).result;
});
}

Expand All @@ -172,10 +172,12 @@ function elementRulesAllowDependency({
isMatch,
rulesMainKey: mainKey,
}) {
const targetElement = elementToGetRulesFrom(element, dependency, mainKey);
const [result, report, ruleReport] = getElementRules(
elementToGetRulesFrom(element, dependency, mainKey),
targetElement,
options,
mainKey,
targetElement === element ? dependency : element,
).reduce(
(allowed, rule) => {
if (rule.disallow) {
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
76 changes: 76 additions & 0 deletions test/rules/layered/entry-point.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const { ENTRY_POINT: RULE } = require("../../../src/constants/rules");
const { SETTINGS, createRuleTester, pathResolvers } = require("../../support/helpers");

const rule = require(`../../../src/rules/${RULE}`);

const { absoluteFilePath } = pathResolvers("layered");

const settings = SETTINGS.layered;

// https://github.com/javierbrea/eslint-plugin-boundaries/issues/340
const options = [
{
// disallow all entry-points by default
default: "disallow",
rules: [
{
target: ["modules"],
allow: "**",
},
{
target: [
// Any element, except the same as target
["modules", { elementName: "!(${from.elementName})" }],
],
// Any file, except index.js
disallow: "!(index.js)",
},
],
},
];

const ruleTester = createRuleTester(settings);

ruleTester.run(RULE, rule, {
valid: [
// helper can be imported inside the same module
{
filename: absoluteFilePath("modules/module-a/components/ComponentA.js"),
code: "import { someHelper } from '../helpers.js'",
options,
},
// helper can be imported from the pubic module API, defined in index.js
{
filename: absoluteFilePath("modules/module-b/components/ComponentB.js"),
code: "import { someHelper } from 'modules/module-a'",
options,
},
],
invalid: [
// Any other file than index.js can't be imported from other module
{
filename: absoluteFilePath("modules/module-b/components/ComponentB.js"),
code: "import { someHelper } from 'modules/module-a/helpers.js'",
options,
errors: [
{
message:
"The entry point 'helpers.js' is not allowed in elements of type 'modules' with elementName '!(module-a)'. Disallowed in rule 2",
type: "Literal",
},
],
},
{
filename: absoluteFilePath("modules/module-b/components/ComponentB.js"),
code: "import { someHelper } from 'modules/module-a/components/ComponentA.js'",
options,
errors: [
{
message:
"The entry point 'components' is not allowed in elements of type 'modules' with elementName '!(module-a)'. Disallowed in rule 2",
type: "Literal",
},
],
},
],
});
16 changes: 16 additions & 0 deletions test/support/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,22 @@ const SETTINGS = {
},
},
},
layered: {
"boundaries/elements": [
{
type: "modules",
mode: "file",
pattern: ["modules/*/**", "modules/*.*"],
capture: ["elementName"],
},
],
"import/resolver": {
"eslint-import-resolver-node": {},
[path.resolve(process.cwd(), "resolver-legacy-alias")]: {
modules: `./${codeFilePath("layered", "modules")}`,
},
},
},
};

const TYPESCRIPT_SETTINGS = {
Expand Down

0 comments on commit 0779f76

Please sign in to comment.