Commit 3a3bbbd2 authored by Florent Chehab's avatar Florent Chehab

Merge branch 'frontend_linting' into 'master'

Frontend linting

Closes #40

See merge request rex-dri/rex-dri!43
parents 7c509208 4acba3d0
# editorconfig.org
root = true
[*]
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.py]
indent_size = 4
[*.js]
indent_size = 2
[*.json]
indent_size = 2
\ No newline at end of file
stages: stages:
- test - test
- syntaxe - linting
- doc - doc
- deploy - deploy
...@@ -27,7 +27,7 @@ testing: ...@@ -27,7 +27,7 @@ testing:
- docker - docker
flake8: flake8:
stage: syntaxe stage: linting
image: python:3.6.5-jessie image: python:3.6.5-jessie
script: script:
- pip install flake8 - pip install flake8
...@@ -35,6 +35,14 @@ flake8: ...@@ -35,6 +35,14 @@ flake8:
tags: tags:
- docker - docker
eslint:
stage: linting
image: pipelinecomponents/eslint:latest
script:
- cd frontend && npm run lint
tags:
- docker
pages: pages:
stage: doc stage: doc
image: floawfloaw/plantuml image: floawfloaw/plantuml
...@@ -50,7 +58,7 @@ pages: ...@@ -50,7 +58,7 @@ pages:
paths: paths:
- public - public
expire_in: 1 month expire_in: 1 month
only: only:
- master - master
tags: tags:
- docker - docker
module.exports = {
"env": {
"browser": true,
"es6": true,
},
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"plugins": [
"react"
],
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
],
"react/no-unescaped-entities": "warn",
"react/prop-types": "warn",
"react/no-deprecated": "warn"
}
};
This diff is collapsed.
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
"description": "[![build](/../badges/master/build.svg)](https://gitlab.utc.fr/chehabfl/outgoing_rex/pipelines) [![coverage](/../badges/master/coverage.svg)](https://chehabfl.gitlab.utc.fr/outgoing_rex/) [![License](https://img.shields.io/badge/License-BSD%202--Clause-green.svg)](https://opensource.org/licenses/BSD-2-Clause)", "description": "[![build](/../badges/master/build.svg)](https://gitlab.utc.fr/chehabfl/outgoing_rex/pipelines) [![coverage](/../badges/master/coverage.svg)](https://chehabfl.gitlab.utc.fr/outgoing_rex/) [![License](https://img.shields.io/badge/License-BSD%202--Clause-green.svg)](https://opensource.org/licenses/BSD-2-Clause)",
"main": "manage.py", "main": "manage.py",
"scripts": { "scripts": {
"lint": "eslint \"./src/**/*.js\"",
"lint-fix": "eslint \"./src/**/*.js\" --fix",
"dev": "webpack --mode development", "dev": "webpack --mode development",
"build": "webpack --mode production", "build": "webpack --mode production",
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
...@@ -45,6 +47,7 @@ ...@@ -45,6 +47,7 @@
"devDependencies": { "devDependencies": {
"autoprefixer": "^9.1.5", "autoprefixer": "^9.1.5",
"babel-core": "^6.26.3", "babel-core": "^6.26.3",
"babel-eslint": "^10.0.1",
"babel-loader": "^7.1.5", "babel-loader": "^7.1.5",
"babel-plugin-transform-class-properties": "^6.24.1", "babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-env": "^1.7.0", "babel-preset-env": "^1.7.0",
...@@ -52,8 +55,9 @@ ...@@ -52,8 +55,9 @@
"babel-preset-react": "^6.24.1", "babel-preset-react": "^6.24.1",
"babel-preset-stage-1": "^6.24.1", "babel-preset-stage-1": "^6.24.1",
"css-loader": "^1.0.0", "css-loader": "^1.0.0",
"eslint": "^5.4.0", "eslint": "^5.13.0",
"eslint-config-google": "^0.9.1", "eslint-config-google": "^0.9.1",
"eslint-plugin-react": "^7.12.4",
"file-loader": "^2.0.0", "file-loader": "^2.0.0",
"js-yaml-loader": "^1.0.1", "js-yaml-loader": "^1.0.1",
"mini-css-extract-plugin": "^0.4.2", "mini-css-extract-plugin": "^0.4.2",
......
export const SAVE_MAIN_MAP_POSITION = 'SAVE_MAIN_MAP_POSITION'; export const SAVE_MAIN_MAP_POSITION = "SAVE_MAIN_MAP_POSITION";
export const SAVE_SELECTED_UNIVERSITIES = 'SAVE_SELECTED_UNIVERSITIES'; export const SAVE_SELECTED_UNIVERSITIES = "SAVE_SELECTED_UNIVERSITIES";
export const SAVE_FILTER_CONFIG = 'SAVE_FILTER_CONFIG'; export const SAVE_FILTER_CONFIG = "SAVE_FILTER_CONFIG";
export const SAVE_APP_THEME = 'SAVE_APP_THEME'; export const SAVE_APP_THEME = "SAVE_APP_THEME";
export const SAVE_APP_COLOR_PICKER = 'SAVE_APP_COLOR_PICKER'; export const SAVE_APP_COLOR_PICKER = "SAVE_APP_COLOR_PICKER";
export const SAVE_UNIVERSITY_BEING_VIEWED = 'SAVE_UNIVERSITY_BEING_VIEWED'; export const SAVE_UNIVERSITY_BEING_VIEWED = "SAVE_UNIVERSITY_BEING_VIEWED";
import { import {
SAVE_SELECTED_UNIVERSITIES, SAVE_SELECTED_UNIVERSITIES,
SAVE_FILTER_CONFIG SAVE_FILTER_CONFIG
} from "./action-types"; } from "./action-types";
export function saveSelectedUniversities(new_selection) { export function saveSelectedUniversities(new_selection) {
return { return {
type: SAVE_SELECTED_UNIVERSITIES, type: SAVE_SELECTED_UNIVERSITIES,
new_selection new_selection
}; };
} }
export function saveFilterConfig(config) { export function saveFilterConfig(config) {
return { return {
type: SAVE_FILTER_CONFIG, type: SAVE_FILTER_CONFIG,
config config
}; };
} }
import { import {
SAVE_MAIN_MAP_POSITION SAVE_MAIN_MAP_POSITION
} from "./action-types"; } from "./action-types";
export function saveMainMapPosition(new_position) { export function saveMainMapPosition(new_position) {
return { return {
type: SAVE_MAIN_MAP_POSITION, type: SAVE_MAIN_MAP_POSITION,
new_position new_position
}; };
} }
import { import {
SAVE_SELECTED_UNIVERSITIES, SAVE_SELECTED_UNIVERSITIES,
SAVE_FILTER_CONFIG SAVE_FILTER_CONFIG
} from "./action-types"; } from "./action-types";
export function saveSelectedUniversities(new_selection) { export function saveSelectedUniversities(new_selection) {
return { return {
type: SAVE_SELECTED_UNIVERSITIES, type: SAVE_SELECTED_UNIVERSITIES,
new_selection new_selection
}; };
} }
export function saveFilterConfig(config) { export function saveFilterConfig(config) {
return { return {
type: SAVE_FILTER_CONFIG, type: SAVE_FILTER_CONFIG,
config config
}; };
} }
import { import {
SAVE_APP_THEME, SAVE_APP_THEME,
SAVE_APP_COLOR_PICKER SAVE_APP_COLOR_PICKER
} from "./action-types"; } from "./action-types";
export function saveAppTheme(theme) { export function saveAppTheme(theme) {
return { return {
type: SAVE_APP_THEME, type: SAVE_APP_THEME,
theme theme
}; };
} }
export function saveAppColorPicker(s) { export function saveAppColorPicker(s) {
return { return {
type: SAVE_APP_COLOR_PICKER, type: SAVE_APP_COLOR_PICKER,
state: s state: s
}; };
} }
import { import {
SAVE_UNIVERSITY_BEING_VIEWED SAVE_UNIVERSITY_BEING_VIEWED
} from "./action-types"; } from "./action-types";
export function saveUniversityBeingViewed(univId) { export function saveUniversityBeingViewed(univId) {
return { return {
type: SAVE_UNIVERSITY_BEING_VIEWED, type: SAVE_UNIVERSITY_BEING_VIEWED,
univId univId
}; };
} }
...@@ -9,7 +9,7 @@ function _isReading(status, type) { ...@@ -9,7 +9,7 @@ function _isReading(status, type) {
return { return {
type, type,
status status
} };
} }
function _readFailed(failed, error, type) { function _readFailed(failed, error, type) {
...@@ -17,7 +17,7 @@ function _readFailed(failed, error, type) { ...@@ -17,7 +17,7 @@ function _readFailed(failed, error, type) {
type, type,
failed, failed,
error error
} };
} }
function _readSucceeded(data, type) { function _readSucceeded(data, type) {
...@@ -82,7 +82,7 @@ export default class CrudActions { ...@@ -82,7 +82,7 @@ export default class CrudActions {
readAllSucceeded, readAllSucceeded,
this.setInvalidatedAll.bind(this), this.setInvalidatedAll.bind(this),
readAllFailed readAllFailed
) );
} }
...@@ -116,7 +116,7 @@ export default class CrudActions { ...@@ -116,7 +116,7 @@ export default class CrudActions {
readSpecificSucceeded, readSpecificSucceeded,
this.setInvalidatedSpecific.bind(this), this.setInvalidatedSpecific.bind(this),
readSpecificFailed readSpecificFailed
) );
} }
...@@ -182,7 +182,7 @@ export default class CrudActions { ...@@ -182,7 +182,7 @@ export default class CrudActions {
isCreating, isCreating,
createSucceeded, createSucceeded,
createFailed createFailed
) );
} }
/** /**
...@@ -218,7 +218,7 @@ export default class CrudActions { ...@@ -218,7 +218,7 @@ export default class CrudActions {
} }
self._checkNotReadonly(); self._checkNotReadonly();
if (!'id' in data) { if (!("id" in data)) {
throw Error("When updating an object, an id is expected in the data"); throw Error("When updating an object, an id is expected in the data");
} }
...@@ -228,7 +228,7 @@ export default class CrudActions { ...@@ -228,7 +228,7 @@ export default class CrudActions {
isUpdating, isUpdating,
updateSucceeded, updateSucceeded,
updateFailed updateFailed
) );
} }
/////////// ///////////
...@@ -246,10 +246,10 @@ export default class CrudActions { ...@@ -246,10 +246,10 @@ export default class CrudActions {
return { return {
type: this.types.isInvalidatedAll, type: this.types.isInvalidatedAll,
isInvalidated: bool isInvalidated: bool
} };
} }
/** /**
* Function to tell the store that this element has been invalidated relative to "specific" * Function to tell the store that this element has been invalidated relative to "specific"
* *
* @param {boolean} bool * @param {boolean} bool
...@@ -260,6 +260,6 @@ export default class CrudActions { ...@@ -260,6 +260,6 @@ export default class CrudActions {
return { return {
type: this.types.isInvalidatedSpecific, type: this.types.isInvalidatedSpecific,
isInvalidated: bool isInvalidated: bool
} };
} }
} }
\ No newline at end of file
import { combineReducers } from 'redux'; import { combineReducers } from "redux";
import getCrudActionTypes from "./getCrudActionTypes"; import getCrudActionTypes from "./getCrudActionTypes";
import SmartActions from "./SmartActions"; import SmartActions from "./SmartActions";
...@@ -6,47 +6,47 @@ import SmartActions from "./SmartActions"; ...@@ -6,47 +6,47 @@ import SmartActions from "./SmartActions";
// generic function helpers // generic function helpers
function failed(state, action, type) { function failed(state, action, type) {
switch (action.type) { switch (action.type) {
case type: case type:
return { return {
failed: action.failed, failed: action.failed,
error: action.error error: action.error
} };
default: default:
return state; return state;
} }
} }
function succeeded(state, action, type) { function succeeded(state, action, type) {
switch (action.type) { switch (action.type) {
case type: case type:
return { return {
data: action.data, data: action.data,
readAt: (new Date()).getTime() readAt: (new Date()).getTime()
} };
default: default:
return state; return state;
} }
} }
function is(state, action, type) { function is(state, action, type) {
switch (action.type) { switch (action.type) {
case type: case type:
return action.status; return action.status;
default: default:
return state; return state;
} }
} }
function invalidate(state, action, type) { function invalidate(state, action, type) {
switch (action.type) { switch (action.type) {
case type: case type:
return action.isInvalidated; return action.isInvalidated;
default: default:
return state; return state;
} }
} }
...@@ -150,7 +150,7 @@ export default class CrudReducers { ...@@ -150,7 +150,7 @@ export default class CrudReducers {
readSucceeded: readSpecificSucceeded, readSucceeded: readSpecificSucceeded,
readFailed: readSpecificFailed, readFailed: readSpecificFailed,
isInvalidated: isInvalidatedSpecific, isInvalidated: isInvalidatedSpecific,
} };
// Add only appropriate reducers // Add only appropriate reducers
if (this.readOnly !== true) { if (this.readOnly !== true) {
......
import Cookies from 'js-cookie'; import Cookies from "js-cookie";
// TODO uodate parameters name to match new CRUD actions // TODO uodate parameters name to match new CRUD actions
...@@ -19,7 +19,7 @@ export default class SmartActions { ...@@ -19,7 +19,7 @@ export default class SmartActions {
} }
/** /**
* Generic function for handling a GET request to the API * Generic function for handling a GET request to the API
* *
* @param {string} pk * @param {string} pk
* @param {string} api_end_point * @param {string} api_end_point
...@@ -32,11 +32,11 @@ export default class SmartActions { ...@@ -32,11 +32,11 @@ export default class SmartActions {
* @memberof SmartActions * @memberof SmartActions
*/ */
_FetchData(pk, api_end_point, _IsLoading, _FetchDataSuccess, _Invalidated, _HasError, pk_required = false) { _FetchData(pk, api_end_point, _IsLoading, _FetchDataSuccess, _Invalidated, _HasError, pk_required = false) {
if (pk_required && (typeof pk == 'undefined')) { if (pk_required && (typeof pk == "undefined")) {
throw "pk shouldn't be empty when requesting a specific element"; throw "pk shouldn't be empty when requesting a specific element";
} }
if (pk != "") { if (pk != "") {
api_end_point += pk + '/'; api_end_point += pk + "/";
} }