Skip to content
This repository has been archived by the owner on Apr 21, 2021. It is now read-only.

refactor: refactoring code to prepare js linter #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Ignore coverage files
coverage
node_modules
dist
jest.config.js
webpack.config.js
test/**/*.js
167 changes: 167 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"env": {
"browser": true,
"jasmine": true,
"node": true,
"protractor": true
},
"rules": {
"strict": 2,

// Possible Errors
"comma-dangle": 2,
"no-cond-assign": 2,
"no-console": 2,
"no-control-regex": 2,
"no-debugger": 2,
"no-dupe-args": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty-character-class": 2,
"no-empty": 2,
"no-ex-assign": 2,
"no-extra-boolean-cast": 2,
"no-extra-parens": 2,
"no-extra-semi": 2,
"no-func-assign": 2,
"no-inner-declarations": 2,
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-negated-in-lhs": 2,
"no-obj-calls": 2,
"no-regex-spaces": 2,
"no-sparse-arrays": 2,
"no-unexpected-multiline": 2,
"no-unreachable": 2,
"use-isnan": 2,
"valid-jsdoc": 2,
"valid-typeof": 2,

// Best Practices
"accessor-pairs": 2,
"block-scoped-var": 2,
"complexity": [2, 8],
"consistent-return": 2,
"curly": 2,
"default-case": 2,
"dot-location": [2, "property"],
"dot-notation": 2,
"eqeqeq": 2,
"guard-for-in": 2,
"no-alert": 2,
"no-caller": 2,
"no-case-declarations": 2,
"no-div-regex": 2,
"no-else-return": 2,
"no-empty-pattern": 2,
"no-eq-null": 2,
"no-eval": 2,
"no-extra-bind": 2,
"no-fallthrough": 2,
"no-floating-decimal": 2,
"no-implied-eval": 2,
"no-invalid-this": 2,
"no-iterator": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-loop-func": 2,
"no-magic-numbers": [2, { "ignore": [-1, 0, 1, 100] }],
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-native-reassign": 2,
"no-new-func": 2,
"no-new-wrappers": 2,
"no-new": 2,
"no-octal-escape": 2,
"no-octal": 2,
"no-param-reassign": [2, { "props": false }],
"no-proto": 2,
"no-redeclare": 2,
"no-return-assign": 2,
"no-script-url": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-throw-literal": 2,
"no-unused-expressions": 2,
"no-useless-call": 2,
"no-useless-concat": 2,
"no-void": 2,
"no-with": 2,
"radix": [2, "as-needed"],
"vars-on-top": 2,
"wrap-iife": 2,

// Variables
"no-catch-shadow": 2,
"no-delete-var": 2,
"no-label-var": 2,
"no-shadow-restricted-names": 2,
"no-shadow": 2,
"no-undef-init": 2,
"no-undef": 2,
"no-undefined": 2,
"no-unused-vars": 2,
"no-use-before-define": [2, "nofunc"],

// Stylistic Issues
"array-bracket-spacing": [2, "never"],
"brace-style": 2,
"camelcase": 2,
"comma-spacing": [2, { "before": false, "after": true }],
"comma-style": [2, "last"],
"computed-property-spacing": [2, "never"],
"eol-last": 2,
"func-style": [2, "declaration"],
"indent": [2, 4, { "SwitchCase": 1 }],
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"linebreak-style": [2, "unix"],
"max-depth": [2, 5],
"new-cap": 2,
"new-parens": 2,
"no-array-constructor": 2,
"no-bitwise": 2,
"no-continue": 2,
"no-mixed-spaces-and-tabs": 2,
"no-multiple-empty-lines": [2, { "max": 1, "maxEOF": 1 }],
"no-nested-ternary": 2,
"no-new-object": 2,
"no-spaced-func": 2,
"no-trailing-spaces": 2,
"no-unneeded-ternary": [2, { "defaultAssignment": true }],
"one-var": [2, "never"],
"padded-blocks": [2, "never"],
"quote-props": [2, "as-needed"],
"quotes": [2, "single"],
"semi-spacing": 2,
"semi": [2, "always"],
"space-before-blocks": 2,
"space-before-function-paren": [2, "never"],
"space-in-parens": [2, "never"],

// ECMAScript 6
"arrow-body-style": [2, "always"],
"arrow-spacing": [2, { "before": true, "after": true }],
"constructor-super": 2,
"no-confusing-arrow": 2,
"no-constant-condition": 2,
"no-class-assign": 2,
"no-const-assign": 2,
"no-dupe-class-members": 2,
"no-this-before-super": 2,
"no-var": 2,
"prefer-arrow-callback": 2,
"prefer-const": 2
},
"globals": {
"browser": true,
"angular": true,
"inject": true,
"Keycloak": true,
"MessageFormat": true,
"moment": true
}
}
14 changes: 11 additions & 3 deletions example/components/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ class MyMap {

init() {
const script = document.createElement('script');
script.setAttribute('src', `../dist/${this.attr.provider}.js`)
script.setAttribute('src', `../dist/${this.attr.provider}.js`);
document.head.appendChild(script);

script.addEventListener('load', () => {
//eslint-disable-next-line no-undef
this.map = new BatMap(
this.el,
this.attr.apiKey,
Expand All @@ -27,7 +28,11 @@ class MyMap {
}

initMap() {
this.map.setMapOptions(this.attr.options, this.attr.markers, this.attr.labels);
this.map.setMapOptions(
this.attr.options,
this.attr.markers,
this.attr.labels
);

this.map.initMap();

Expand All @@ -39,7 +44,10 @@ class MyMap {

this.map.addMarkers();

this.map.fitBounds(this.map.getBounds(), this.attr.options.locationZoom);
this.map.fitBounds(
this.map.getBounds(),
this.attr.options.locationZoom
);
}
}

Expand Down
77 changes: 53 additions & 24 deletions example/components/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ class MyMap {

init() {
const script = document.createElement('script');
script.setAttribute('src', `../dist/${this.attr.provider}.js`)
script.setAttribute('src', `../dist/${this.attr.provider}.js`);
document.head.appendChild(script);

script.addEventListener('load', () => {
//eslint-disable-next-line no-undef
this.map = new BatMap(
this.el,
this.attr.apiKey,
Expand All @@ -27,12 +28,24 @@ class MyMap {
}

bindEvents() {
[].forEach.call(document.querySelectorAll('[data-location]'), location => {
const id = location.getAttribute('data-location');
location.addEventListener('click', this.handleClickOnLocation(id));
location.addEventListener('mouseenter', this.handleMouseEnterOnLocation(id));
location.addEventListener('mouseleave', this.handleMouseLeaveOnLocation(id));
});
[].forEach.call(
document.querySelectorAll('[data-location]'),
location => {
const id = location.getAttribute('data-location');
location.addEventListener(
'click',
this.handleClickOnLocation(id)
);
location.addEventListener(
'mouseenter',
this.handleMouseEnterOnLocation(id)
);
location.addEventListener(
'mouseleave',
this.handleMouseLeaveOnLocation(id)
);
}
);
}

initMap() {
Expand All @@ -57,7 +70,12 @@ class MyMap {
}

setMapOptions() {
this.map.setMapOptions(this.attr.options, this.attr.markers, this.attr.labels, this.attr.clusters);
this.map.setMapOptions(
this.attr.options,
this.attr.markers,
this.attr.labels,
this.attr.clusters
);
}

setPoints() {
Expand Down Expand Up @@ -103,18 +121,19 @@ class MyMap {
}

geolocateOnMap() {
if(this.attr.showPosition) {
this.map.getGeolocation()
if (this.attr.showPosition) {
this.map
.getGeolocation()
.then(position => {
this.map.addUserMarker(position.coords, 'user');
})
.catch(error => {
console.error(`geolocateOnMap(): ${error.message}`);
return false;
throw new Error(`geolocateOnMap(): ${error.message}`);
});
} else {
return false;
}
return true;
}

panToAllMarkers() {
Expand All @@ -137,25 +156,31 @@ class MyMap {
this.scrollToLocation(marker.id);
this.highlightLocation(marker.id, true);
}
}
};
}

handleMouseEnterOnMarker(marker) {
return () => {
if (this.getMarkerIconType(marker) !== 'active' && this.getMarkerIconType(marker) !== 'hover') {
if (
this.getMarkerIconType(marker) !== 'active' &&
this.getMarkerIconType(marker) !== 'hover'
) {
this.setIconOnMarker(marker, 'hover');
this.highlightLocation(marker.id);
}
}
};
}

handleMouseLeaveOnMarker(marker) {
return () => {
if (this.getMarkerIconType(marker) !== 'active' && this.getMarkerIconType(marker) !== 'default') {
if (
this.getMarkerIconType(marker) !== 'active' &&
this.getMarkerIconType(marker) !== 'default'
) {
this.setIconOnMarker(marker, 'default');
this.highlightLocation(false);
}
}
};
}

// NOTE: LocationOnMap
Expand All @@ -171,7 +196,7 @@ class MyMap {
this.focusOnMarker(marker);
this.highlightLocation(id, true);
}
}
};
}

handleMouseEnterOnLocation(id) {
Expand All @@ -185,7 +210,7 @@ class MyMap {
this.highlightLocation(id, true);
}
}
}
};
}

handleMouseLeaveOnLocation(id) {
Expand All @@ -199,7 +224,7 @@ class MyMap {
this.highlightLocation(id, true);
}
}
}
};
}

highlightLocation(id = false, isActive = false) {
Expand All @@ -214,9 +239,12 @@ class MyMap {
location.classList.add('hover');

if (isActive) {
[].forEach.call(document.querySelectorAll('[data-location]'), l => {
l.classList.remove('active');
});
[].forEach.call(
document.querySelectorAll('[data-location]'),
l => {
l.classList.remove('active');
}
);
location.classList.add('active');
}
}
Expand All @@ -229,7 +257,8 @@ class MyMap {

if (location && list) {
list.scrollTo({
top: location.offsetTop - location.clientHeight - list.offsetTop,
top:
location.offsetTop - location.clientHeight - list.offsetTop,
behavior: 'smooth'
});
}
Expand Down
Loading