Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
enable eslint prefer-includes check.
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Raggi <roberto.raggi@here.com>
  • Loading branch information
robertoraggi committed Aug 19, 2020
1 parent 04162d3 commit 148feb2
Show file tree
Hide file tree
Showing 23 changed files with 56 additions and 65 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/restrict-plus-operands": "off",
"@typescript-eslint/dot-notation": "off",
"@typescript-eslint/prefer-includes": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/prefer-optional-chain": "off",
"@typescript-eslint/no-floating-promises": "off",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export namespace WorkerServiceProtocol {
* Test if `error` thrown by [[CreateServiceRequest]] was caused by unknown type of service.
*/
export function isUnknownServiceError(error: Error): boolean {
return /unknown targetServiceType requested: /.test(error.message);
return error.message.includes("unknown targetServiceType requested: ");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const operators = {
const left = context.evaluate(call.args[0]);
const right = context.evaluate(call.args[1]);
if (typeof left === "string" && typeof right === "string") {
return left.indexOf(right) !== -1;
return left.includes(right);
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion @here/harp-examples/lib/PerformanceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export namespace PerformanceUtils {
const availableExtensions = context.getSupportedExtensions();
if (
availableExtensions !== null &&
availableExtensions.indexOf("WEBGL_debug_renderer_info") > -1
availableExtensions.includes("WEBGL_debug_renderer_info")
) {
const infoExtension = context.getExtension("WEBGL_debug_renderer_info");
if (infoExtension !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export namespace LinesPointsFeaturesExample {
const featuresList: MapViewFeature[] = [];
for (const type of Object.keys(features)) {
for (const featureName of Object.keys(features[type])) {
const name = featureName.indexOf("unknown") === -1 ? featureName : undefined;
const name = !featureName.includes("unknown") ? featureName : undefined;
// snippet:harp_demo_features_linespoints_1.ts
const feature = new MapViewLineFeature(features[type][featureName], { name, type });
// end:harp_demo_features_linespoints_1.ts
Expand Down
16 changes: 8 additions & 8 deletions @here/harp-examples/src/datasource_features_polygons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export namespace PolygonsFeaturesExample {
setCaption();

function getJoiningDate(j: number) {
let joiningDate = steps.find(year => EU.steps[year].joining.indexOf(j) > -1)!;
let joiningDate = steps.find(year => EU.steps[year].joining.includes(j))!;
const actualDate = EU.steps[joiningDate].actualJoining;
if (actualDate !== undefined) {
joiningDate = actualDate;
Expand All @@ -94,11 +94,11 @@ export namespace PolygonsFeaturesExample {
const features: MapViewFeature[] = [];
let age = steps.length;
let k = 0;
while (EU.steps[steps[k]].joining.indexOf(j) === -1) {
while (!EU.steps[steps[k]].joining.includes(j)) {
age--;
k++;
}
if (stateGroup.indexOf("germany") > -1) {
if (stateGroup.includes("germany")) {
age = steps.length;
}

Expand Down Expand Up @@ -152,17 +152,17 @@ export namespace PolygonsFeaturesExample {
if (step !== steps[currentStep]) {
dataSourcesToReShow.push(...EU.steps[step].joining);
for (const leaving of EU.steps[step].leaving) {
if (dataSourcesToReShow.indexOf(leaving) > -1) {
if (dataSourcesToReShow.includes(leaving)) {
dataSourcesToReShow.splice(dataSourcesToReShow.indexOf(leaving), 1);
}
}
} else {
dataSourcesToShow.push(...EU.steps[step].joining);
for (const leaving of EU.steps[step].leaving) {
if (dataSourcesToReShow.indexOf(leaving) > -1) {
if (dataSourcesToReShow.includes(leaving)) {
dataSourcesToReShow.splice(dataSourcesToReShow.indexOf(leaving), 1);
}
if (dataSourcesToShow.indexOf(leaving) > -1) {
if (dataSourcesToShow.includes(leaving)) {
dataSourcesToShow.splice(dataSourcesToShow.indexOf(leaving), 1);
}
}
Expand All @@ -171,14 +171,14 @@ export namespace PolygonsFeaturesExample {
}
dataSourcesToReShow.forEach(value => {
const datasource = featuresDataSources[value];
if (displayedDataSourceCache.indexOf(datasource) < 0) {
if (!displayedDataSourceCache.includes(datasource)) {
map.addDataSource(datasource);
displayedDataSourceCache.push(datasource);
}
});
dataSourcesToShow.forEach(value => {
const datasource = featuresDataSources[value];
if (displayedDataSourceCache.indexOf(datasource) < 0) {
if (!displayedDataSourceCache.includes(datasource)) {
map.addDataSource(datasource);
displayedDataSourceCache.push(datasource);
}
Expand Down
6 changes: 1 addition & 5 deletions @here/harp-examples/src/performance_benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -978,11 +978,7 @@ export namespace PerformanceBenchmark {
}

let str = value.toFixed(digits);
while (
str.length > 1 &&
str.indexOf(".") >= 0 &&
(str.endsWith("0") || str.endsWith("."))
) {
while (str.length > 1 && str.includes(".") && (str.endsWith("0") || str.endsWith("."))) {
str = str.substr(0, str.length - 1);
}

Expand Down
2 changes: 1 addition & 1 deletion @here/harp-mapview/lib/DecodedTileHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ function applyShaderTechniqueToMaterial(technique: ShaderTechnique, material: TH
// Omit base color and related transparency attributes if its defined in technique
if (
baseColorPropName === propertyName ||
(hasBaseColor && TRANSPARENCY_PROPERTY_KEYS.indexOf(propertyName) !== -1)
(hasBaseColor && TRANSPARENCY_PROPERTY_KEYS.includes(propertyName))
) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions @here/harp-mapview/lib/EventDispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class EventDispatcher {
if (listeners === undefined) {
return false;
}
return listener !== undefined ? listeners.indexOf(listener) >= 0 : true;
return listener !== undefined ? listeners.includes(listener) : true;
}

/**
Expand All @@ -52,7 +52,7 @@ export class EventDispatcher {
listeners = [];
this.m_listeners.set(type, listeners);
}
if (listeners.indexOf(listener) === -1) {
if (!listeners.includes(listener)) {
listeners.push(listener);
}
}
Expand Down
4 changes: 2 additions & 2 deletions @here/harp-mapview/lib/MapView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2207,7 +2207,7 @@ export class MapView extends EventDispatcher {
});
})
.then(() => {
const alreadyRemoved = this.m_tileDataSources.indexOf(dataSource) === -1;
const alreadyRemoved = !this.m_tileDataSources.includes(dataSource);
if (alreadyRemoved) {
return;
}
Expand Down Expand Up @@ -2963,7 +2963,7 @@ export class MapView extends EventDispatcher {
}

// Add as datasource if it was not added before
const isPresent = this.m_tileDataSources.indexOf(elevationSource) !== -1;
const isPresent = this.m_tileDataSources.includes(elevationSource);
if (!isPresent) {
await this.addDataSource(elevationSource);
}
Expand Down
2 changes: 1 addition & 1 deletion @here/harp-mapview/lib/geometry/TileGeometryCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ export class TileGeometryCreator {
}

if (
group.createdOffsets!.indexOf(tile.offset) !== -1 ||
group.createdOffsets!.includes(tile.offset) ||
technique._kindState === false ||
(techniqueFilter !== undefined && !techniqueFilter(technique))
) {
Expand Down
2 changes: 1 addition & 1 deletion @here/harp-mapview/lib/image/ImageCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class ImageCache {
registerImage(mapView: MapView, url: string, imageData?: ImageData | ImageBitmap): ImageItem {
let imageCacheItem = this.findImageCacheItem(url);
if (imageCacheItem !== undefined) {
if (mapView !== undefined && imageCacheItem.mapViews.indexOf(mapView) < 0) {
if (mapView !== undefined && !imageCacheItem.mapViews.includes(mapView)) {
imageCacheItem.mapViews.push(mapView);
}
return imageCacheItem.imageItem;
Expand Down
2 changes: 1 addition & 1 deletion @here/harp-mapview/lib/image/MapViewImageCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class MapViewImageCache {
}
const oldNames = this.m_url2Name.get(url);
if (oldNames !== undefined) {
if (oldNames.indexOf(name) < 0) {
if (!oldNames.includes(name)) {
oldNames.push(name);
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions @here/harp-mapview/test/TextElementsRendererTestFixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ export class TestFixture {
for (let i = 0; i < allElements.length; ++i) {
const element = allElements[i];
const addElement = elementEnabled[i];
const elementPresent = [...tileElementGroups.groups.values()].find(
group => group.elements.indexOf(element) !== -1
const elementPresent = [...tileElementGroups.groups.values()].find(group =>
group.elements.includes(element)
);
if (addElement && !elementPresent) {
tile.addTextElement(element);
Expand Down
4 changes: 2 additions & 2 deletions @here/harp-mapview/test/VisibleTileSetTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ describe("VisibleTileSet", function() {
dsValid: DataSource[]
) => {
dstl.forEach(dataSourceTileList => {
if (dsSkipped.indexOf(dataSourceTileList.dataSource) !== -1) {
if (dsSkipped.includes(dataSourceTileList.dataSource)) {
dataSourceTileList.visibleTiles.forEach(tile => {
expect(tile["skipRendering"]).is.true;
});
} else if (dsValid.indexOf(dataSourceTileList.dataSource) !== -1) {
} else if (dsValid.includes(dataSourceTileList.dataSource)) {
dataSourceTileList.visibleTiles.forEach(tile => {
expect(tile["skipRendering"]).is.false;
});
Expand Down
2 changes: 1 addition & 1 deletion @here/harp-test-utils/lib/TestDataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const testResourcesRoot =
export function getTestResourceUrl(module: string, fileName: string) {
const modulePath = path.dirname(require.resolve(module + "/package.json"));
const resultPath = path.join(testResourcesRoot, modulePath, fileName);
if (resultPath.indexOf("\\") !== -1) {
if (resultPath.includes("\\")) {
// node-fetch on windows, needs proper URL
return "file://" + resultPath.replace(/\\/g, "/");
} else {
Expand Down
2 changes: 1 addition & 1 deletion @here/harp-text-canvas/lib/rendering/FontCatalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ export class FontCatalog {
if (glyph === undefined) {
let glyphPromise = this.m_loadingGlyphs.get(glyphHash);
if (glyphPromise === undefined) {
if (font.charset.indexOf(String.fromCodePoint(codePoint)) === -1) {
if (!font.charset.includes(String.fromCodePoint(codePoint))) {
const replacementGlyph = this.createReplacementGlyph(codePoint, char, font);
fontGlyphMap!.set(codePoint, replacementGlyph);
this.m_glyphTextureCache.add(glyphHash, replacementGlyph);
Expand Down
4 changes: 2 additions & 2 deletions @here/harp-vectortile-datasource/lib/OmvDataFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ export class OmvGenericFeatureFilter implements OmvFeatureFilter {
continue;
}

if (item.geometryTypes !== undefined && item.geometryTypes.indexOf(geometryType) >= 0) {
if (item.geometryTypes !== undefined && item.geometryTypes.includes(geometryType)) {
return true;
}
}
Expand All @@ -680,7 +680,7 @@ export class OmvGenericFeatureFilter implements OmvFeatureFilter {
continue;
}

if (item.geometryTypes !== undefined && item.geometryTypes.indexOf(geometryType) >= 0) {
if (item.geometryTypes !== undefined && item.geometryTypes.includes(geometryType)) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion @here/harp-vectortile-datasource/lib/OmvDebugLabelsTile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ export class OmvDebugLabelsTile extends Tile {
const elementIndex = this.preparedTextPaths.indexOf(textPath);

const createDebugInfo =
(!textFilter || (text && text.indexOf(textFilter) >= 0)) &&
(!textFilter || (text && text.includes(textFilter))) &&
(indexFilter === undefined || indexFilter === elementIndex);

if (createDebugInfo) {
Expand Down
2 changes: 1 addition & 1 deletion @here/harp-vectortile-datasource/lib/OmvDecoderDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export namespace OmvFilterString {
case OmvFilterString.StringMatch.EndsWith:
return filterString.value.endsWith(str);
default:
return str.indexOf(filterString.value) >= 0;
return str.includes(filterString.value);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion @here/harp-vectortile-datasource/lib/OmvRestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ export class OmvRestClient implements DataProvider {

private addQueryParams(url: string, queryParams: QueryParameters): string {
let queryString = "";
let sep = url.indexOf("?") !== -1 ? "&" : "?";
let sep = url.includes("?") ? "&" : "?";
for (const prop in queryParams) {
if (!queryParams.hasOwnProperty(prop)) {
continue;
Expand Down
48 changes: 23 additions & 25 deletions @here/harp-vectortile-datasource/lib/OmvTomTomFeatureModifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class OmvTomTomFeatureModifier extends OmvGenericFeatureModifier {
}

private isIndustrial(layer: string): boolean {
return layer.indexOf("Industrial") >= 0 || layer === "Airport";
return layer.includes("Industrial") || layer === "Airport";
}

private isPark(layer: string): boolean {
Expand All @@ -163,8 +163,8 @@ export class OmvTomTomFeatureModifier extends OmvGenericFeatureModifier {
layer === "City park" ||
layer === "National park" ||
layer === "Regional park" ||
layer.indexOf("grass") >= 0 ||
layer.indexOf("greens") >= 0
layer.includes("grass") ||
layer.includes("greens")
);
}

Expand Down Expand Up @@ -192,7 +192,7 @@ export class OmvTomTomFeatureModifier extends OmvGenericFeatureModifier {
}

private isRoadLabel(layer: string): boolean {
return layer.indexOf("road label") >= 0;
return layer.includes("road label");
}

private isRoadPath(layer: string): boolean {
Expand All @@ -210,31 +210,31 @@ export class OmvTomTomFeatureModifier extends OmvGenericFeatureModifier {

private isRoadStreet(layer: string): boolean {
return (
layer.indexOf("Minor local road") >= 0 ||
layer.indexOf("minor local road") >= 0 ||
layer.indexOf("Toll local road") >= 0 ||
layer.indexOf("Local road") >= 0
layer.includes("Minor local road") ||
layer.includes("minor local road") ||
layer.includes("Toll local road") ||
layer.includes("Local road")
);
}

private isRoadPrimary(layer: string): boolean {
return (
layer.indexOf("Major local road") >= 0 ||
layer.indexOf("Major road") >= 0 ||
layer.indexOf("major road") >= 0 ||
layer.indexOf("Motorway") >= 0 ||
layer.indexOf("motorway") >= 0 ||
layer.indexOf("International road") >= 0 ||
layer.indexOf("international road") >= 0
layer.includes("Major local road") ||
layer.includes("Major road") ||
layer.includes("major road") ||
layer.includes("Motorway") ||
layer.includes("motorway") ||
layer.includes("International road") ||
layer.includes("international road")
);
}

private isRoadSecondary(layer: string): boolean {
return (
layer.indexOf("connecting road") >= 0 ||
layer.indexOf("Connecting road") >= 0 ||
layer.indexOf("secondary road") >= 0 ||
layer.indexOf("Secondary road") >= 0
layer.includes("connecting road") ||
layer.includes("Connecting road") ||
layer.includes("secondary road") ||
layer.includes("Secondary road")
);
}

Expand Down Expand Up @@ -287,9 +287,7 @@ export class OmvTomTomFeatureModifier extends OmvGenericFeatureModifier {

private isPoiLabel(layer: string): boolean {
return (
layer === "National park name" ||
layer === "Landmark label" ||
layer.indexOf("label") >= 0
layer === "National park name" || layer === "Landmark label" || layer.includes("label")
);
}

Expand All @@ -298,14 +296,14 @@ export class OmvTomTomFeatureModifier extends OmvGenericFeatureModifier {
}

private isBuilding(layer: string): boolean {
return layer.indexOf("building") >= 0;
return layer.includes("building");
}

private isTunnel(layer: string): boolean {
return layer.indexOf("tunnel") >= 0;
return layer.includes("tunnel");
}

private isBridge(layer: string): boolean {
return layer.indexOf("bridge") >= 0;
return layer.includes("bridge");
}
}
4 changes: 1 addition & 3 deletions @here/harp-vectortile-datasource/test/OmvTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ export class RoadFeatureFilter implements OmvFeatureModifier {
doProcessLineFeature(_layer: string, env: MapEnv): boolean {
const roadClass = env.lookup("class");
const isRoad =
roadClass !== undefined &&
roadClass !== null &&
roadClass.toString().indexOf("rail") < 0;
roadClass !== undefined && roadClass !== null && !roadClass.toString().includes("rail");
return isRoad;
}

Expand Down

0 comments on commit 148feb2

Please sign in to comment.