Skip to content

Commit

Permalink
Merge pull request #4970 from camptocamp/more-typecheck
Browse files Browse the repository at this point in the history
 Add ESLint Plugin TypeScript
  • Loading branch information
sbrunner committed Jun 27, 2019
2 parents 13a9091 + 35cbc9a commit aabdba7
Show file tree
Hide file tree
Showing 49 changed files with 216 additions and 171 deletions.
22 changes: 22 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
extends:
- openlayers
- plugin:@typescript-eslint/recommended
env:
jquery: true
parserOptions:
ecmaVersion: 2017
project: ./tsconfig.json
rules:
no-console: 0
comma-dangle: 0
Expand All @@ -13,3 +15,23 @@ rules:
- error
- code: 110
ignoreComments: true
'@typescript-eslint/indent': 0
'@typescript-eslint/no-unused-vars': 0
'@typescript-eslint/no-use-before-define': 0
'@typescript-eslint/camelcase': 0
'@typescript-eslint/no-unnecessary-type-assertion':
- error
'@typescript-eslint/no-for-in-array':
- error
'@typescript-eslint/no-this-alias':
- error
'@typescript-eslint/no-useless-constructor':
- error
'@typescript-eslint/prefer-for-of':
- error
'@typescript-eslint/prefer-includes':
- error
'@typescript-eslint/prefer-string-starts-ends-with':
- error
'@typescript-eslint/restrict-plus-operands':
- error
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ gh-pages: .build/python-venv.timestamp
$(GMF_TEST_JS_FILES) \
$(GMF_JS_FILES) \
$(GMF_EXAMPLES_JS_FILES) \
$(GMF_APPS_JS_FILES) \
$(WEBPACK_CONFIG_FILES)
$(GMF_APPS_JS_FILES)
./node_modules/.bin/eslint $(filter-out .build/node_modules.timestamp $(ESLINT_CONFIG_FILES), $^)
touch $@

Expand Down
4 changes: 2 additions & 2 deletions contribs/gmf/apps/desktop_alt/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Controller extends AbstractDesktopController {
const fill = new Fill({color: [255, 255, 255, 0.6]});
const stroke = new Stroke({color: [255, 0, 0, 1], width: 2});
const image = new Circle({fill, radius, stroke});
const default_search_style = new Style({
const defaultSearchStyle = new Style({
fill,
image,
stroke
Expand All @@ -128,7 +128,7 @@ class Controller extends AbstractDesktopController {
* @export
*/
this.searchStyles = {
'default': default_search_style
'default': defaultSearchStyle
};

// Allow angular-gettext-tools to collect the strings to translate
Expand Down
2 changes: 1 addition & 1 deletion contribs/gmf/examples/objecteditinghub.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ MainController.appendParams = function(uri, params) {
// remove any trailing ? or &
uri = uri.replace(/[?&]$/, '');
// append ? or & depending on whether uri has existing parameters
uri = uri.indexOf('?') === -1 ? `${uri}?` : `${uri}&`;
uri = uri.includes('?') ? `${uri}&` : `${uri}?`;
return uri + qs;
};

Expand Down
2 changes: 1 addition & 1 deletion contribs/gmf/examples/xsdattributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function MainController($timeout, gmfThemes, gmfXSDAttributes) {
flatNodes.forEach((node) => {
const groupNode = /** @type {import('gmf/themes.js').GmfGroup} */(node);
// Get an array of all layers
if (groupNode.children === undefined && layerNames.indexOf(node.name) !== -1) {
if (groupNode.children === undefined && layerNames.includes(node.name)) {
this.layers.push(/** @type {import('gmf/themes.js').GmfLayer} */(node));
}
});
Expand Down
2 changes: 1 addition & 1 deletion contribs/gmf/src/authentication/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class AuthenticationService extends olEventsEventTarget {
* @return {angular.IPromise<void>} Promise.
*/
logout() {
const noReload = this.noReloadRole_ ? this.getRolesNames().indexOf(this.noReloadRole_) !== -1 : false;
const noReload = this.noReloadRole_ ? this.getRolesNames().includes(this.noReloadRole_) : false;
const url = `${this.baseUrl_}/${RouteSuffix.LOGOUT}`;
return this.$http_.get(url, {withCredentials: true}).then(() => {
this.resetUser_(noReload);
Expand Down
1 change: 1 addition & 0 deletions contribs/gmf/src/controllers/AbstractMobileController.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export class AbstractMobileController extends AbstractAppController {
*/
openNavMenu(target) {
const navElements = document.getElementsByClassName('gmf-mobile-nav-button');
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < navElements.length; i++) {
const element = /** @type {HTMLElement} */(navElements[i]);
if (element.dataset && element.dataset.target === target) {
Expand Down
2 changes: 1 addition & 1 deletion contribs/gmf/src/controllers/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import angular from 'angular';
function bootstrap(module) {
// Hack to make the bootstrap type check working with polyfill.io
const oldObjectToString = Object.prototype.toString;
if (oldObjectToString.toString().indexOf('[native code]') < 0) {
if (!oldObjectToString.toString().includes('[native code]')) {
Object.prototype.toString = function() {
if (this === null) {
return '[object Null]';
Expand Down
17 changes: 12 additions & 5 deletions contribs/gmf/src/datasource/Manager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import angular from 'angular';
import gmfDatasourceOGC from 'gmf/datasource/OGC.js';
import GmfDatasourceOGC from 'gmf/datasource/OGC.js';
import gmfDatasourceWFSAliases from 'gmf/datasource/WFSAliases.js';
import gmfLayertreeSyncLayertreeMap, {getLayer} from 'gmf/layertree/SyncLayertreeMap.js';
import gmfLayertreeTreeManager from 'gmf/layertree/TreeManager.js';
Expand All @@ -21,6 +21,7 @@ import {clear as clearObject} from 'ol/obj.js';
import olLayerImage from 'ol/layer/Image.js';
import olSourceImageWMS from 'ol/source/ImageWMS.js';
import olSourceTileWMS from 'ol/source/TileWMS.js';
import BaseLayer from 'ol/layer/Base.js';


/**
Expand Down Expand Up @@ -254,7 +255,13 @@ export class DatasourceManager {
handleDimensionsChange_() {

// Create a layer list to update each one only once
/**
* @type {BaseLayer[]}
*/
const layers = [];
/**
* @type {string[]}
*/
const layerIds = [];

const dataSources = this.dataSources_.getArray();
Expand All @@ -267,7 +274,7 @@ export class DatasourceManager {
return;
}
const id = olUtilGetUid(layer);
if (layerIds.indexOf(id) == -1) {
if (!layerIds.includes(id)) {
layers.push(layer);
layerIds.push(id);
}
Expand Down Expand Up @@ -667,7 +674,7 @@ export class DatasourceManager {
options.wmtsUrl = wmtsUrl;
}
// Create the data source and add it to the cache
this.dataSourcesCache_[id] = new gmfDatasourceOGC(options);
this.dataSourcesCache_[id] = new GmfDatasourceOGC(options);
}

/**
Expand Down Expand Up @@ -884,8 +891,8 @@ export class DatasourceManager {
}
const gmfLayerWMS = /** @type {import('gmf/themes.js').GmfLayerWMS} */(dataSource.gmfLayer);
if (olUtilGetUid(dsLayer) == olUtilGetUid(layer) &&
layer.get('querySourceIds').indexOf(String(dataSource.id)) >= 0 &&
gmfLayerWMS.layers.split(',').indexOf(wmsLayerName) >= 0) {
layer.get('querySourceIds').includes(String(dataSource.id)) &&
gmfLayerWMS.layers.split(',').includes(wmsLayerName)) {

const id = olUtilGetUid(dataSource.gmfLayer);
const item = this.treeCtrlCache_[id];
Expand Down
4 changes: 2 additions & 2 deletions contribs/gmf/src/datasource/OGC.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import ngeoDatasourceOGC from 'ngeo/datasource/OGC.js';
* @private
* @hidden
*/
class gmfDatasourceOGC extends ngeoDatasourceOGC {
class GmfDatasourceOGC extends ngeoDatasourceOGC {

/**
* A `gmf.datasource.OGC` extends a `ngeo.datasource.OGC` and
Expand Down Expand Up @@ -113,4 +113,4 @@ class gmfDatasourceOGC extends ngeoDatasourceOGC {

}

export default gmfDatasourceOGC;
export default GmfDatasourceOGC;
2 changes: 1 addition & 1 deletion contribs/gmf/src/disclaimer/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ DisclaimerController.prototype.$onDestroy = function() {
DisclaimerController.prototype.showDisclaimerMessage_ = function(msg) {
msg = this.gettextCatalog_.getString(msg);
if (this.external) {
if (this.msgs_.indexOf(msg) < 0) {
if (!this.msgs_.includes(msg)) {
this.msgs_.push(msg);
}
this.msg = `${this.sce_.trustAsHtml(this.msgs_.join('<br />'))}`;
Expand Down
7 changes: 6 additions & 1 deletion contribs/gmf/src/editing/editFeatureComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,13 @@ Controller.prototype.save = function() {
if (attribute.format) {
if (this.feature.get(attribute.name)) {
const name = this.feature.get(attribute.name);
console.assert(typeof name == 'string');
if (typeof name == 'string') {
throw new Error('Wrong name type');
}
const value = dateFormatter.parseDate(name, attribute.format);
if (value === null) {
throw new Error('Missing date');
}
let jsonFormat = 'Y-m-d\\TH:i:s';
if (attribute.type === 'date') {
jsonFormat = 'Y-m-d';
Expand Down
6 changes: 3 additions & 3 deletions contribs/gmf/src/filters/filterselectorComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import gmfDatasourceDataSourceBeingFiltered from 'gmf/datasource/DataSourceBeing

import gmfDatasourceHelper from 'gmf/datasource/Helper.js';

import gmfDatasourceOGC from 'gmf/datasource/OGC.js';
import GmfDatasourceOGC from 'gmf/datasource/OGC.js';
import gmfFiltersSavedFilters from 'gmf/filters/SavedFilters.js';

import ngeoMessageModalComponent from 'ngeo/message/modalComponent.js';
Expand Down Expand Up @@ -410,7 +410,7 @@ class FilterSelectorController {
handleDataSourcesAdd_(evt) {
if (evt instanceof CollectionEvent) {
const dataSource = evt.element;
if (dataSource instanceof gmfDatasourceOGC) {
if (dataSource instanceof GmfDatasourceOGC) {
this.registerDataSource_(dataSource);
}
}
Expand All @@ -429,7 +429,7 @@ class FilterSelectorController {
handleDataSourcesRemove_(evt) {
if (evt instanceof CollectionEvent) {
const dataSource = evt.element;
if (dataSource instanceof gmfDatasourceOGC) {
if (dataSource instanceof GmfDatasourceOGC) {
this.unregisterDataSource_(dataSource);
}
}
Expand Down
50 changes: 32 additions & 18 deletions contribs/gmf/src/lidarprofile/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ export class LidarprofileManager {
const domain = this.plot.updateScaleX.domain();
pytreeLinestring = '';

for (let i = 0; i < clippedLine.length; i++) {
pytreeLinestring += `{${clippedLine[i][0]},${clippedLine[i][1]}},`;
for (const clipped of clippedLine) {
pytreeLinestring += `{${clipped[0]},${clipped[1]}},`;
}
pytreeLinestring = pytreeLinestring.substr(0, pytreeLinestring.length - 1);
maxLODWith = this.utils.getNiceLOD(domain[1] - domain[0], max_levels);
Expand Down Expand Up @@ -364,8 +364,8 @@ export class LidarprofileManager {

const uInt8header = new Uint8Array(profile, 4, headerSize);
let strHeaderLocal = '';
for (let i = 0; i < uInt8header.length; i++) {
strHeaderLocal += String.fromCharCode(uInt8header[i]);
for (const header of uInt8header) {
strHeaderLocal += String.fromCharCode(header);
}

try {
Expand Down Expand Up @@ -403,11 +403,14 @@ export class LidarprofileManager {

const attr = jHeader.pointAttributes;
const attributes = [];
for (let j = 0; j < attr.length; j++) {
if (this.config.serverConfig.point_attributes[attr[j]] != undefined) {
attributes.push(this.config.serverConfig.point_attributes[attr[j]]);
for (const att of attr) {
if (this.config.serverConfig.point_attributes[att] != undefined) {
attributes.push(this.config.serverConfig.point_attributes[att]);
}
}
/**
* @type {number}
*/
const scale = jHeader.scale;

if (jHeader.points < 3) {
Expand All @@ -422,41 +425,52 @@ export class LidarprofileManager {
const byteOffset = bytesPerPoint * i;
const view = new DataView(buffer, byteOffset, bytesPerPoint);
let aoffset = 0;
for (let k = 0; k < attributes.length; k++) {

if (attributes[k].value == 'POSITION_PROJECTED_PROFILE') {
for (const attribute of attributes) {
if (attribute.value == 'POSITION_PROJECTED_PROFILE') {
const udist = view.getUint32(aoffset, true);
const dist = udist * scale;
points.distance.push(Math.round(100 * (distanceOffset + dist)) / 100);
this.profilePoints.distance.push(Math.round(100 * (distanceOffset + dist)) / 100);

} else if (attributes[k].value == 'CLASSIFICATION') {
} else if (attribute.value == 'CLASSIFICATION') {
const classif = view.getUint8(aoffset);
points.classification.push(classif);
this.profilePoints.classification.push(classif);

} else if (attributes[k].value == 'INTENSITY') {
} else if (attribute.value == 'INTENSITY') {
const intensity = view.getUint8(aoffset);
points.intensity.push(intensity);
this.profilePoints.intensity.push(intensity);

} else if (attributes[k].value == 'COLOR_PACKED') {
} else if (attribute.value == 'COLOR_PACKED') {
const r = view.getUint8(aoffset);
const g = view.getUint8(aoffset + 1);
const b = view.getUint8(aoffset + 2);
points.color_packed.push([r, g, b]);
this.profilePoints.color_packed.push([r, g, b]);

} else if (attributes[k].value == 'POSITION_CARTESIAN') {
const x = view.getInt32(aoffset, true) * scale + jHeader.boundingBox.lx;
const y = view.getInt32(aoffset + 4, true) * scale + jHeader.boundingBox.ly;
const z = view.getInt32(aoffset + 8, true) * scale + jHeader.boundingBox.lz;
} else if (attribute.value == 'POSITION_CARTESIAN') {
const lx = jHeader.boundingBox.lx;
if (typeof lx != 'number') {
throw new Error('Wrong lx type');
}
const ly = jHeader.boundingBox.ly;
if (typeof ly != 'number') {
throw new Error('Wrong ly type');
}
const lz = jHeader.boundingBox.lz;
if (typeof lz != 'number') {
throw new Error('Wrong lz type');
}
const x = view.getInt32(aoffset, true) * scale + lx;
const y = view.getInt32(aoffset + 4, true) * scale + ly;
const z = view.getInt32(aoffset + 8, true) * scale + lz;
points.coords.push([x, y]);
points.altitude.push(z);
this.profilePoints.altitude.push(z);
this.profilePoints.coords.push([x, y]);
}
aoffset = aoffset + attributes[k].bytes;
aoffset = aoffset + attribute.bytes;
}
}

Expand Down
20 changes: 10 additions & 10 deletions contribs/gmf/src/lidarprofile/Plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export default class {

/**
* d3.scaleLinear X scale.
* @type {Function}
* @type {function(number): number}
*/
this.updateScaleX = () => undefined;
this.updateScaleX = (x) => x;

/**
* d3.scaleLinear Y scale.
Expand All @@ -54,9 +54,9 @@ export default class {

/**
* d3.scaleLinear Y scale.
* @type {Function}
* @type {function(number): number}
*/
this.updateScaleY = () => undefined;
this.updateScaleY = (y) => y;

/**
* The material used for the drawing process. Initialized in the setup
Expand Down Expand Up @@ -309,11 +309,11 @@ export default class {
const yAxis = d3axisLeft(this.scaleY)
.tickSize(-this.width_);

const new_scaleX = tr.rescaleX(this.scaleX);
const new_scaleY = tr.rescaleY(this.scaleY);
const newScaleX = tr.rescaleX(this.scaleX);
const newScaleY = tr.rescaleY(this.scaleY);

svg.select('.x.axis').call(/** @type {any} */ (xAxis.scale(new_scaleX)));
svg.select('.y.axis').call(/** @type {any} */ (yAxis.scale(new_scaleY)));
svg.select('.x.axis').call(/** @type {any} */ (xAxis.scale(newScaleX)));
svg.select('.y.axis').call(/** @type {any} */ (yAxis.scale(newScaleY)));

const canvas = d3select('#gmf-lidarprofile-container .lidar-canvas');
const canvasEl = /** @type {HTMLCanvasElement} */(canvas.node());
Expand All @@ -327,8 +327,8 @@ export default class {
.style('opacity', '0.5')
.style('stroke', '#b7cff7');

this.updateScaleX = new_scaleX;
this.updateScaleY = new_scaleY;
this.updateScaleX = newScaleX;
this.updateScaleY = newScaleY;

}

Expand Down

0 comments on commit aabdba7

Please sign in to comment.