-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d8a09f
commit 9229337
Showing
16 changed files
with
109 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
export const ESLINT_ERRORS = { | ||
invalidName: `🔥 Invalid {{selectorKey}} name, allowed formats = {{formatWithoutReferences}} 🔥`, | ||
prohibitedSelector: `🔥 The use of '{{selectorKey}}' is prohibited in this file. 🔥{{error}}`, | ||
prohibitedSelectorRoot: `🔥 The use of '{{selectorKey}}' is prohibited in the root of the file. 🔥{{error}}`, | ||
prohibitedSelectorExport: `🔥 Exporting '{{selectorKey}}' is prohibited in this file. 🔥{{error}}`, | ||
invalidName: `🔥 Invalid {{selectorType}} name, allowed formats = {{formatWithoutReferences}} 🔥`, | ||
prohibitedSelector: `🔥 The use of '{{selectorType}}' is prohibited in this file. 🔥{{error}}`, | ||
prohibitedSelectorRoot: `🔥 The use of '{{selectorType}}' is prohibited in the root of the file. 🔥{{error}}`, | ||
prohibitedSelectorExport: `🔥 Exporting '{{selectorType}}' is prohibited in this file. 🔥{{error}}`, | ||
rootSelectorsLimits: | ||
"🔥 The limit for the given selectors in the root of the file has been exceeded. 🔥\n{{error}}\n\n", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 29 additions & 6 deletions
35
...s/fileComposition/helpers/validateFile/helpers/validateRules/helpers/isCorrectSelector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,53 @@ | ||
import { WILDCARD_REGEX } from "consts"; | ||
|
||
import { getInvalidRegexError } from "errors/getInvalidRegexError"; | ||
|
||
import { isRegexInvalid } from "helpers/isRegexInvalid"; | ||
|
||
import { | ||
Selector, | ||
SelectorType, | ||
} from "rules/fileComposition/fileComposition.types"; | ||
|
||
interface IsCorrectSelectorProps { | ||
selector: Selector | Selector[]; | ||
selectorKey: SelectorType; | ||
selectorType: SelectorType; | ||
expressionName?: string; | ||
} | ||
|
||
export const isCorrectSelector = ({ | ||
selector, | ||
selectorKey, | ||
selectorType, | ||
expressionName, | ||
}: IsCorrectSelectorProps): boolean => { | ||
if (typeof selector === "string") return selector === selectorKey; | ||
if (typeof selector === "string") return selector === selectorType; | ||
|
||
if (!Array.isArray(selector)) { | ||
if (!expressionName) return false; | ||
|
||
return ( | ||
selector.type === selectorKey && selector.limitTo.includes(expressionName) | ||
if (typeof selector.limitTo === "string") { | ||
const regexImproved = selector.limitTo | ||
.replaceAll("*", WILDCARD_REGEX) | ||
.replaceAll(`*${WILDCARD_REGEX}`, "*"); | ||
|
||
if (isRegexInvalid(regexImproved)) | ||
throw getInvalidRegexError(regexImproved); | ||
|
||
const finalRegex = new RegExp(`^${regexImproved}$`, "g"); | ||
|
||
return selector.type === selectorType && finalRegex.test(expressionName); | ||
} | ||
|
||
return selector.limitTo.some((limitTo) => | ||
isCorrectSelector({ | ||
selector: { type: "variableExpression", limitTo }, | ||
selectorType, | ||
expressionName, | ||
}), | ||
); | ||
} | ||
|
||
return selector.some((sel) => | ||
isCorrectSelector({ selector: sel, selectorKey, expressionName }), | ||
isCorrectSelector({ selector: sel, selectorType, expressionName }), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
.../validateFolderStructure/helpers/validatePath/helpers/validateName/validateName.consts.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export const WILDCARD_REGEX = "(([^/]*)+)"; | ||
export const DOT_CHARACTER_REGEX = "\\."; |
Oops, something went wrong.