Skip to content

Commit

Permalink
[TASK] Implement @typescript-eslint/prefer-string-starts-ends-with
Browse files Browse the repository at this point in the history
…rule

The eslint configuration now takes the rule
`@typescript-eslint/prefer-string-starts-ends-with` [1] into account,
enforcing the usage of `startsWith()` and `endWith()` over index
checking in strings.

[1] https://typescript-eslint.io/rules/prefer-string-starts-ends-with

Resolves: #103374
Releases: main, 12.4
Change-Id: I88640f71cbe960db2a2e2b162410ff5a79e7c55c
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83437
Tested-by: Andreas Kienast <[email protected]>
Reviewed-by: Anja Leichsenring <[email protected]>
Tested-by: core-ci <[email protected]>
Tested-by: Anja Leichsenring <[email protected]>
Reviewed-by: Benjamin Franzke <[email protected]>
Tested-by: Garvin Hicking <[email protected]>
Reviewed-by: Garvin Hicking <[email protected]>
Reviewed-by: Andreas Kienast <[email protected]>
  • Loading branch information
andreaskienast committed Mar 14, 2024
1 parent 79329c7 commit a88c843
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions Build/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = {
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/member-ordering": "error",
"@typescript-eslint/prefer-readonly": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/naming-convention": [
"error",
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class TsCodeCompletion {
let childNode;
// if the childnode has a value and there is a part of a reference operator ('<')
// and it does not look like a html tag ('>')
if (childNodes[key].v && childNodes[key].v[0] === '<' && childNodes[key].v.indexOf('>') === -1) {
if (childNodes[key].v && childNodes[key].v.startsWith('<') && !childNodes[key].v.includes('>')) {
const path = childNodes[key].v.replace(/</, '').trim();
// if there are still whitespaces it's no path
if (path.indexOf(' ') === -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ export class TsParser {
if (i < tokens.length && tokens[i].string.length > 0) {
const tokenValue = tokens[i].string;

if (tokenValue[0] === '#') {
if (tokenValue.startsWith('#')) {
stack.push('#');
} else if (tokenValue === '(') {
stack.push('(');
} else if (tokenValue[0] === '/' && tokenValue[1] === '*') {
} else if (tokenValue.startsWith('/*')) {
stack.push('/*');
} else if (tokenValue === '{') {
// TODO: ignore whole block if wrong whitespaces in this line
Expand Down Expand Up @@ -237,7 +237,7 @@ export class TsParser {
if (tokenValue === ')') {
stack.popIfLastElementEquals('(');
}
if (tokenValue[0] === '*' && tokenValue[1] === '/') {
if (tokenValue.startsWith('*/')) {
stack.popIfLastElementEquals('/*');
ignoreLine = true;
}
Expand Down
2 changes: 1 addition & 1 deletion Build/Sources/TypeScript/backend/form-engine-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ export default (function() {
FormEngineValidation.parseDouble = function(value: number|string|boolean, precision: number = 2): string {
let theVal = '' + value;
theVal = theVal.replace(/[^0-9,.-]/g, '');
const negative = theVal.substring(0, 1) === '-';
const negative = theVal.startsWith('-');
theVal = theVal.replace(/-/g, '');
theVal = theVal.replace(/,/g, '.');
if (theVal.indexOf('.') === -1) {
Expand Down
2 changes: 1 addition & 1 deletion Build/Sources/TypeScript/rte_ckeditor/rte-link-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class RteLinkBrowser {
link = linkMatch[1] + linkMatch[2];
const paramsPrefix = linkMatch[2].length > 0 ? '&' : '?';
if (queryParams.length > 0) {
if (queryParams[0] === '&') {
if (queryParams.startsWith('&')) {
queryParams = queryParams.substr(1);
}
// If params is set, append it
Expand Down

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

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

Loading

0 comments on commit a88c843

Please sign in to comment.