sonarjs/regex-complexity
eslint-plugin-sonarjs
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/regex-complexity": "error",
},
},
];Regular expressions should not be too complicated
const datePattern = /^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[13-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/;
if (dateString.match(datePattern)) {
handleDate(dateString);
}const datePattern = /^\d{1,2}([-/.])\d{1,2}\1\d{1,4}$/;
if (dateString.match(datePattern)) {
const dateParts = dateString.split(/[-/.]/);
const day = parseInt(dateParts[0]);
const month = parseInt(dateParts[1]);
const year = parseInt(dateParts[2]);
// Put logic to validate and process the date based on its integer parts here
}Examples from the ESLint documentation.
sonarjs/regex-complexity
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/regex-complexity": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Wallet phrases should not be hard-coded
"Array.reduce()" calls should include an initial value
A new session should be created during user authentication
Temporary files should not be created in publicly writable directories
Character classes in regular expressions should not contain only one character