Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade webpack to v5, setup ESLint #81

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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/test/**
19 changes: 19 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true
},
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"allowImportExportEverywhere": true
},
"extends": "eslint:recommended",
"rules": {
"no-eval": ["error"],
"no-trailing-spaces": "error",
"no-irregular-whitespace": "off"
}
}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"scripts": {
"test": "./node_modules/mocha/bin/mocha --recursive --require @babel/register --require ignore-styles",
"build": "npm run test && ./node_modules/webpack-cli/bin/cli.js",
"watch": "./node_modules/webpack-cli/bin/cli.js --watch"
"watch": "./node_modules/webpack-cli/bin/cli.js --watch",
"eslint-fix": "npx eslint --fix src/**"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -50,12 +51,15 @@
"devDependencies": {
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"@babel/eslint-parser": "^7.17.0",
"@babel/preset-env": "^7.12.1",
"@babel/register": "^7.12.1",
"assert": "^2.0.0",
"autoprefixer": "^9.8.0",
"babel-loader": "^8.1.0",
"css-loader": "^3.5.3",
"eslint": "^8.13.0",
"eslint-webpack-plugin": "^3.1.1",
"esm": "^3.2.22",
"ignore-styles": "^5.0.1",
"mini-css-extract-plugin": "^0.9.0",
Expand All @@ -66,7 +70,7 @@
"sass-loader": "^10.2.1",
"terser-webpack-plugin": "^3.0.2",
"uglify-js": "^3.11.5",
"webpack": "^4.44.2",
"webpack": "^5.72.0",
"webpack-cli": "^3.3.11"
}
}
2 changes: 1 addition & 1 deletion src/actions/pagination.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setHistory, HISTORY_PARAMETERS } from '../util/history';
import {setHistory, HISTORY_PARAMETERS} from '../util/history';

export const SET_PAGE = 'SET_PAGE';

Expand Down
3 changes: 1 addition & 2 deletions src/actions/search.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global window */
import { WARMUP_QUERY_PREFIX } from '../index';
import { setHistory, HISTORY_PARAMETERS } from '../util/history';
import { sendSearchStats } from '../util/analytics';
Expand Down Expand Up @@ -62,7 +61,7 @@ export function search(client, keyword, onResultsScrollTo, appendResults, isHist
}
}

export function searchFetchStart(keyword) {
export function searchFetchStart() {
return {
type: SEARCH_FETCH_START
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/activefilters/activefilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default class ActiveFilters {

const clearAll = container.querySelector('[data-clearall]');
if (clearAll) {
clearAll.addEventListener('click', (e) => this.reduxStore.dispatch(clearSelected(true)));
clearAll.addEventListener('click', () => this.reduxStore.dispatch(clearSelected(true)));
}
}

Expand Down
1 change: 0 additions & 1 deletion src/components/facets/facets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import './facets.scss';
import handlebars from 'handlebars';
import { FACETS_TEMPLATE } from './templates';
import { toggleFacetFilter } from '../../actions/filters';
import { search } from '../../actions/search';
import { observeStoreByKey } from '../../store';
import { validateContainer } from '../../util/dom';
import {createFilterObject} from "../filters/filterstateobserver";
Expand Down
2 changes: 1 addition & 1 deletion src/components/filters/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export default class Filters {
// Clear button
const button = container.querySelector('button');
if (button) {
button.addEventListener('click', (e) => this.reduxStore.dispatch(setRangeFilter(this.conf.field, null, null)));
button.addEventListener('click', () => this.reduxStore.dispatch(setRangeFilter(this.conf.field, null, null)));
}
}

Expand Down
1 change: 0 additions & 1 deletion src/components/hierarchicalfacets/hierarchicalfacets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import './hierarchicalfacets.scss';
import handlebars from 'handlebars';
import { FACETS_TEMPLATE, SUB_HIERARCHICAL_FACETS_TEMPLATE } from './templates';
import { toggleHierarchicalFacetFilter } from '../../actions/filters';
import { search } from '../../actions/search';
import { observeStoreByKey } from '../../store';
import { validateContainer } from '../../util/dom';
import {createFilterObject} from "../filters/filterstateobserver";
Expand Down
2 changes: 1 addition & 1 deletion src/components/loadmore/loadmore.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class LoadMore {
if (this.conf.type === LOAD_MORE_TYPE.BUTTON) {
const button = container.querySelector('button');
if (button) {
button.onclick = (e) => this.loadMore();
button.onclick = () => this.loadMore();
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/components/searchfield/searchfield.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global window */
import './searchfield.scss';
import { SEARCHFIELD_TEMPLATE } from './templates';
import handlebars from 'handlebars';
Expand Down Expand Up @@ -126,7 +125,7 @@ export default class SearchField {
this.field.onkeypress = (e) => this.onkeypress(e);
this.field.onkeyup = (e) => this.onkeyup(e);
this.field.onfocus = (e) => this.onfocus(e);
this.field.onblur = (e) => setTimeout(() => this.onblur(), 200); // Possible search button onclick event first
this.field.onblur = () => setTimeout(() => this.onblur(), 200); // Possible search button onclick event first

// Event listeners to the possible search button
if (container.querySelector('button')) {
Expand Down
70 changes: 34 additions & 36 deletions src/reducers/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const initialState = {

export default function searchsuggestions(state = initialState, action) {
switch (action.type) {
case AUTOCOMPLETE_FETCH_START:
case AUTOCOMPLETE_FETCH_START: {
// Add to pending requests
let addPendingReq = [...state.pendingRequests];
if (addPendingReq.indexOf(action.jsonKey) === -1) {
Expand All @@ -44,23 +44,23 @@ export default function searchsuggestions(state = initialState, action) {
pendingRequests: addPendingReq,
dropRendering: false
});
}


case AUTOCOMPLETE_SUGGESTIONS_CLEAR:
case AUTOCOMPLETE_SUGGESTIONS_CLEAR: {
return Object.assign({}, state, {
suggestions: [],
activeSuggestionIndex: null
});
}

case AUTOCOMPLETE_CUSTOM_FIELDS_CLEAR:
case AUTOCOMPLETE_CUSTOM_FIELDS_CLEAR: {
return Object.assign({}, state, {
customFields: [],
activeSuggestionIndex: null
});
}


case AUTOCOMPLETE_SUGGESTIONS_RESULTS:

case AUTOCOMPLETE_SUGGESTIONS_RESULTS: {
// Remove suggestion from pending requests
let removePendingSuggestion = [...state.pendingRequests];
if (removePendingSuggestion.indexOf(SUGGESTIONS_JSON_KEY) !== -1) {
Expand All @@ -74,9 +74,9 @@ export default function searchsuggestions(state = initialState, action) {
activeSuggestionIndex: null,
visible: true
});
}


case AUTOCOMPLETE_CUSTOM_FIELDS_RESULTS:
case AUTOCOMPLETE_CUSTOM_FIELDS_RESULTS: {

// Remove suggestion from pending requests
let removePendingCustomFields = [...state.pendingRequests];
Expand All @@ -90,16 +90,16 @@ export default function searchsuggestions(state = initialState, action) {
activeSuggestionIndex: null,
visible: true
});
}


case AUTOCOMPLETE_SEARCH_CLEAR:
case AUTOCOMPLETE_SEARCH_CLEAR: {
return Object.assign({}, state, {
searchResults: {},
searchResultsStats: {}
});
}


case AUTOCOMPLETE_SEARCH_RESULTS:
case AUTOCOMPLETE_SEARCH_RESULTS: {
const nextSearchResults = Object.assign({}, state.searchResults);
nextSearchResults[action.jsonKey] = action.results.hits;
const nextSearchResultsStats = Object.assign({}, state.searchResultsStats);
Expand Down Expand Up @@ -133,43 +133,45 @@ export default function searchsuggestions(state = initialState, action) {
visible: true,
appendResults: action.appendResults === true
});
}


case AUTOCOMPLETE_HIDE:
case AUTOCOMPLETE_HIDE: {

return Object.assign({}, state, {
visible: false,
activeSuggestionIndex: null
});
}

case AUTOCOMPLETE_HIDE_AND_DROP_RENDERING:
case AUTOCOMPLETE_HIDE_AND_DROP_RENDERING: {
return Object.assign({}, state, {
dropRendering: true,
visible: false,
activeSuggestionIndex: null
});
}


case AUTOCOMPLETE_SHOW:
case AUTOCOMPLETE_SHOW: {
return Object.assign({}, state, {
visible: true
});
}


case HIDE_AUTOMATICALLY:
case HIDE_AUTOMATICALLY: {
return Object.assign({}, state, {
hideAutomatically: action.hideAutomatically
});
}


case SET_ACTIVE_SUGGESTION:
case SET_ACTIVE_SUGGESTION: {
return Object.assign({}, state, {
activeSuggestionIndex: action.index,
setSuggestionToSearchField: action.setSuggestionToSearchField
});
}

case KEYBOARD_EVENT:
let nextActiveSuggestion = state.activeSuggestionIndex;
case KEYBOARD_EVENT: {
let nextActiveSuggestion = state.activeSuggestionIndex;
let setSuggestionToSearchField = true;

if (state.suggestions.length && state.customFields.length) {
Expand All @@ -181,22 +183,17 @@ export default function searchsuggestions(state = initialState, action) {
if (action.direction === ARROW_DOWN) {
if (nextActiveSuggestion === null && state[source].length > 0) {
nextActiveSuggestion = 0;
}
else if (nextActiveSuggestion === state[source].length-1) {
} else if (nextActiveSuggestion === state[source].length - 1) {
nextActiveSuggestion = null;
}
else {
} else {
nextActiveSuggestion = nextActiveSuggestion + 1;
}
}
else if (action.direction === ARROW_UP) {
} else if (action.direction === ARROW_UP) {
if (nextActiveSuggestion === null && state[source].length > 0) {
nextActiveSuggestion = state[source].length-1;
}
else if (nextActiveSuggestion === 0) {
nextActiveSuggestion = state[source].length - 1;
} else if (nextActiveSuggestion === 0) {
nextActiveSuggestion = null;
}
else {
} else {
nextActiveSuggestion = nextActiveSuggestion - 1;
}
}
Expand All @@ -205,8 +202,9 @@ export default function searchsuggestions(state = initialState, action) {
return Object.assign({}, state, {
visible: true,
activeSuggestionIndex: nextActiveSuggestion,
setSuggestionToSearchField: true
setSuggestionToSearchField: setSuggestionToSearchField
});
}

default:
return state;
Expand Down
Loading