Skip to content

Commit 4836ee7

Browse files
committed
add rule to prefer includes over indexof plus linting
1 parent 8d03cf7 commit 4836ee7

11 files changed

Lines changed: 12 additions & 11 deletions

File tree

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default tseslint.config({
1919
files: ['ts/**/*.ts'],
2020
ignores: ["**/*.d.ts", "**/*.js", "**/cjs/*"],
2121
"rules": {
22+
"@typescript-eslint/prefer-includes": "error",
2223
"@typescript-eslint/no-explicit-any": "off",
2324
"@typescript-eslint/no-unused-vars": ["error",
2425
{ "varsIgnorePattern": "^_", "argsIgnorePattern": "^_",

ts/a11y/explorer/KeyExplorer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ export class SpeechExplorer
494494
);
495495
while (internal && internal !== this.generators.element) {
496496
const sid = internal.getAttribute('data-semantic-id');
497-
if (dummies.indexOf(sid) !== -1) {
497+
if (dummies.includes(sid)) {
498498
this.current = this.node.querySelector(
499499
`[data-semantic-id="${sid}"]`
500500
);

ts/adaptors/HTMLAdaptor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ export class HTMLAdaptor<
514514
if (node.classList) {
515515
return node.classList.contains(name);
516516
}
517-
return node.className.split(/ /).indexOf(name) >= 0;
517+
return node.className.split(/ /).includes(name);
518518
}
519519

520520
/**

ts/components/package.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export class Package {
230230
//
231231
for (const dependent of dependencies) {
232232
const extension = map.get(dependent) || new Package(dependent, noLoad);
233-
if (this.dependencies.indexOf(extension) < 0) {
233+
if (!this.dependencies.includes(extension)) {
234234
extension.addDependent(this, noLoad);
235235
this.dependencies.push(extension);
236236
if (!extension.isLoaded) {

ts/input/tex/Configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ export class ParserConfiguration {
436436
*/
437437
protected getPackage(name: string): Configuration {
438438
const config = ConfigurationHandler.get(name);
439-
if (config && this.parsers.indexOf(config.parser) < 0) {
439+
if (config && !this.parsers.includes(config.parser)) {
440440
throw Error(`Package ${name} doesn't target the proper parser`);
441441
}
442442
return config;

ts/input/tex/ParseUtil.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const KeyValueTypes: {
8080
oneof: (...values: string[]) =>
8181
new KeyValueType<string>(
8282
'oneof',
83-
(value) => values.indexOf(value) >= 0,
83+
(value) => values.includes(value),
8484
(value) => value
8585
),
8686
dimen: new KeyValueType<string>(
@@ -191,7 +191,7 @@ function readValue(
191191
countBraces = false; // Stop counting start left braces.
192192
break;
193193
default:
194-
if (!braces && end.indexOf(c) !== -1) {
194+
if (!braces && end.includes(c)) {
195195
// End character reached.
196196
return [
197197
removeBraces(value, l3keys ? Math.min(1, start) : start),

ts/input/tex/bussproofs/BussproofsMethods.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function parseFCenterLine(parser: TexParser, name: string): MmlNode {
144144
}
145145
parser.i++;
146146
const axiom = parser.GetUpTo(name, '$');
147-
if (axiom.indexOf('\\fCenter') === -1) {
147+
if (!axiom.includes('\\fCenter')) {
148148
throw new TexError(
149149
'MissingProofCommand',
150150
'Missing %1 in %2.',

ts/input/tex/physics/PhysicsMethods.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function vectorApplication(
137137
let lfence = '',
138138
rfence = '',
139139
arg = '';
140-
const enlarge = fences.indexOf(left) !== -1;
140+
const enlarge = fences.includes(left);
141141
if (left === '{') {
142142
arg = parser.GetArgument(name);
143143
lfence = enlarge ? '\\left\\{' : '';

ts/input/tex/require/RequireConfiguration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function RegisterExtension(jax: TeX<any, any, any>, name: string) {
5656
const required = jax.parseOptions.packageData.get('require')
5757
.required as string[];
5858
const extension = name.substring(require.prefix.length);
59-
if (required.indexOf(extension) < 0) {
59+
if (!required.includes(extension)) {
6060
required.push(extension);
6161
//
6262
// Register any dependencies that were loaded to handle this one,

ts/output/common/Wrappers/mtable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ export function CommonMtableMixin<
10851085
* @override
10861086
*/
10871087
public getColumnWidthsPercent(swidths: string[]): ColumnWidths {
1088-
const hasFit = swidths.indexOf('fit') >= 0;
1088+
const hasFit = swidths.includes('fit');
10891089
const { W } = hasFit ? this.getTableData() : { W: null };
10901090
return Array.from(swidths.keys()).map((i) => {
10911091
const x = swidths[i];

0 commit comments

Comments
 (0)