Commit 6dc73e07 authored by seykron's avatar seykron

Adds eslint and prettier to force coding conventions in the frontend code

parent 1c412b30
Pipeline #176 failed with stages
This diff is collapsed.
module.exports = {
env: {
es6: true,
node: true,
jest: true
},
extends: [
'plugin:vue/recommended', // Vue specific rules (i.e. no v-models on divs)
'eslint:recommended', // default javascript best-practice rules
'prettier/vue', // Vue specific prettier formatting
'plugin:prettier/recommended' // use eslint-plugin-prettier and eslint-config-prettier
],
plugins: [],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly'
},
parserOptions: {
ecmaVersion: 6,
parser: 'babel-eslint'
},
rules: {
'no-prototype-builtins': 'off',
'vue/attributes-order': 'off',
'vue/name-property-casing': ['warn', 'PascalCase'],
'vue/require-prop-types': 'error',
'vue/require-default-prop': 'error',
'filenames/match-exported': 'off',
'no-useless-escape': 'warn',
'no-unused-vars': ['error', { args: 'none', ignoreRestSiblings: true }],
'require-atomic-updates': 'off',
'prettier/prettier': [
'error',
{ singleQuote: true, tabWidth: 4, trailingComma: 'none' }
],
'vue/no-mutating-props': 'warn',
'vue/custom-event-name-casing': 'warn',
'vue/no-unused-properties': [
'error',
{
groups: ['props', 'data', 'computed', 'methods']
}
]
}
};
import { put } from "../../../modules/objectCache";
import {MediaObject} from "../../media/model/MediaObject";
import { put } from '../../../modules/objectCache';
import { MediaObject } from '../../media/model/MediaObject';
/** Represents a user or organization profile that can be placed
* inline in the middle of other content.
*/
export class Profile {
constructor({
id,
userName,
displayName,
photo,
updatedAt
}) {
constructor({ id, userName, displayName, photo, updatedAt }) {
this.id = id;
this.userName = userName;
this.displayName = displayName;
......
import { get } from "../../modules/http";
import { put } from "../../modules/objectCache";
import { Profile } from "./model/Profile";
import { get } from '../../modules/http';
import { put } from '../../modules/objectCache';
import { Profile } from './model/Profile';
function newProfile(model) {
return put(new Profile(model));
......
......@@ -8,7 +8,9 @@ import { DraftCampaign } from './model/DraftCampaign';
import { v4 as uuid } from 'uuid';
async function newCampaign(model, withEndorsements = false) {
const endorsements = withEndorsements ? await endorsementRepository.listPublic(model.id) : [];
const endorsements = withEndorsements
? await endorsementRepository.listPublic(model.id)
: [];
return put(
new Campaign({
...model,
......@@ -45,7 +47,10 @@ export default {
async saveDraft(draft) {
draft.updatedAt = new Date();
await sessionRepository.setAttribute(DRAFT_CAMPAIGN_ATTR, JSON.stringify(draft));
await sessionRepository.setAttribute(
DRAFT_CAMPAIGN_ATTR,
JSON.stringify(draft)
);
return draft;
}
};
import { put } from "../../../modules/objectCache";
import { MediaObject } from "../../media/model/MediaObject";
import { Profile } from "../../accounts/model/Profile";
import { put } from '../../../modules/objectCache';
import { MediaObject } from '../../media/model/MediaObject';
import { Profile } from '../../accounts/model/Profile';
export class Campaign {
constructor({
......@@ -13,7 +13,7 @@ export class Campaign {
targets,
support,
createdAt,
updatedAt,
updatedAt
}) {
this.id = id;
this.friendlyId = friendlyId;
......@@ -21,9 +21,9 @@ export class Campaign {
this.description = description;
this.media = put(new MediaObject(media));
this.coordinator = put(new Profile(coordinator));
this.targets = targets.map(target => put(new Profile(target)));
this.targets = targets.map((target) => put(new Profile(target)));
const endorsements = support.endorsements.map(endorsement => ({
const endorsements = support.endorsements.map((endorsement) => ({
...endorsement,
profile: put(new Profile(endorsement.profile))
}));
......
......@@ -31,7 +31,7 @@ export const Steps = {
const MOCK_TARGETS = [
{
name: "Juan Perez",
name: 'Juan Perez',
photo: undefined
}
];
......@@ -48,7 +48,7 @@ function sortedSteps() {
}
return 0;
});
return sortedSteps.map(stepName => Steps[stepName]);
return sortedSteps.map((stepName) => Steps[stepName]);
}
/** View model to manage the Create Campaign wizard state.
......@@ -67,7 +67,9 @@ export class DraftCampaign {
this.title = title;
this.description = description;
this.selectedTargets = selectedTargets;
this.step = sortedSteps().find(step => step.view === this.stepName) || Steps.SELECT_TITLE;
this.step =
sortedSteps().find((step) => step.view === this.stepName) ||
Steps.SELECT_TITLE;
this._allTargets = MOCK_TARGETS;
this.updatedAt = updatedAt || new Date();
}
......@@ -81,7 +83,7 @@ export class DraftCampaign {
}
const nextStepPos = this.step.position + 1;
const nextStep = sortedSteps().find(step => {
const nextStep = sortedSteps().find((step) => {
return step.position === nextStepPos;
});
this.step = nextStep;
......@@ -95,13 +97,15 @@ export class DraftCampaign {
* @param {number} position Step position to jump to.
*/
goToStep(position) {
const candidateStep = sortedSteps().find(step => {
const candidateStep = sortedSteps().find((step) => {
return step.position === position;
});
const canJump = sortedSteps().every(step =>
(step.position < candidateStep.position && step.validate(this)) ||
step.position >= candidateStep.position
const canJump = sortedSteps().every(
(step) =>
(step.position < candidateStep.position &&
step.validate(this)) ||
step.position >= candidateStep.position
);
if (!canJump) {
......@@ -113,7 +117,9 @@ export class DraftCampaign {
}
async searchTargets(criteria) {
const exists = this._allTargets.some(target => target.name === criteria);
const exists = this._allTargets.some(
(target) => target.name === criteria
);
if (!exists) {
this._allTargets.push({ name: criteria, photo: undefined });
}
......@@ -122,8 +128,10 @@ export class DraftCampaign {
}
updateTargets(targets) {
this.selectedTargets = targets.map(name =>
this._allTargets.find(target => target.name === name
)).filter(Boolean);
this.selectedTargets = targets
.map((name) =>
this._allTargets.find((target) => target.name === name)
)
.filter(Boolean);
}
}
import { post } from "../../modules/http";
import { put } from "../../modules/objectCache";
import { PublicEndorsement } from "./model/PublicEndorsement";
import { post } from '../../modules/http';
import { put } from '../../modules/objectCache';
import { PublicEndorsement } from './model/PublicEndorsement';
import { PageRequest } from '../../modules/paging';
function newEndorsement(model) {
......@@ -12,7 +12,7 @@ export default {
return newEndorsement(
await post(`/api/campaigns/${campaignId}/endorsements`, {
type,
'public': isPublic
public: isPublic
})
);
},
......
import { put } from "../../../modules/objectCache";
import { Profile } from "../../accounts/model/Profile";
import { put } from '../../../modules/objectCache';
import { Profile } from '../../accounts/model/Profile';
export class PublicEndorsement {
constructor({
id,
profile,
campaignId,
type,
createdAt
}) {
constructor({ id, profile, campaignId, type, createdAt }) {
this.id = id;
this.profile = put(new Profile(profile));
this.campaignId = campaignId;
......
import { get, patch } from "../../modules/http";
import { get, patch } from '../../modules/http';
export default {
async getAttribute(name) {
......
......@@ -4,7 +4,7 @@ import VueI18n from 'vue-i18n';
import App from './App';
import 'materialize-css/dist/css/materialize.min.css';
import 'materialize-css/dist/js/materialize.min';
import 'font-awesome/css/font-awesome.min.css'
import 'font-awesome/css/font-awesome.min.css';
import './assets/css/icon.css';
import router from './modules/router';
import { i18n, configureLocale } from './modules/i18n';
......@@ -17,10 +17,10 @@ import VueLogger from 'vuejs-logger';
Vue.use(VueLogger, {
isEnabled: true,
logLevel : 'debug',
stringifyArguments : false,
showLogLevel : true,
showMethodName : false,
logLevel: 'debug',
stringifyArguments: false,
showLogLevel: true,
showMethodName: false,
separator: '|',
showConsoleColors: true
});
......@@ -31,8 +31,8 @@ Vue.use(VMarkdown);
/* eslint-disable no-new */
new Vue({
el: '#app',
template: '<App/>',
components: { App },
template: '<App/>',
router,
i18n: i18n(),
async beforeMount() {
......
const ENV_NAME = "JAVA_ENV";
const ENV_NAME = 'JAVA_ENV';
const currentEnv = process.env[ENV_NAME] || 'localdev';
const Environment = {
......
......@@ -13,24 +13,22 @@ export function humanTime(seconds) {
const times = [
seconds / 60 / 60 / 24 / 365, // years
seconds / 60 / 60 / 24 / 30, // months
seconds / 60 / 60 / 24 / 7, // weeks
seconds / 60 / 60 / 24, // days
seconds / 60 / 60, // hours
seconds / 60, // minutes
seconds // seconds
seconds / 60 / 60 / 24 / 30, // months
seconds / 60 / 60 / 24 / 7, // weeks
seconds / 60 / 60 / 24, // days
seconds / 60 / 60, // hours
seconds / 60, // minutes
seconds // seconds
];
const names = ['year', 'month', 'week', 'day', 'hour', 'minute', 'second'];
for (const i = 0; i < names.length; i++) {
for (let i = 0; i < names.length; i++) {
const time = Math.floor(times[i]);
let name = names[i];
if (time > 1)
name += 's';
if (time > 1) name += 's';
if (time >= 1)
return time + ' ' + name + ' ' + suffix;
if (time >= 1) return time + ' ' + name + ' ' + suffix;
}
return '0 seconds ' + suffix;
}
......@@ -7,7 +7,7 @@ const localeConfig = {
};
function loadMessages(locale) {
return require(`../lang/${locale}.yaml`)
return require(`../lang/${locale}.yaml`);
}
export function i18n() {
......@@ -29,11 +29,18 @@ export function i18n() {
*/
export async function configureLocale(component, user, defaultLocale) {
try {
const resolvedLocale = (user && user.locale) || defaultLocale || navigator.language;
component.$i18n.setLocaleMessage(resolvedLocale, loadMessages(resolvedLocale));
const resolvedLocale =
(user && user.locale) || defaultLocale || navigator.language;
component.$i18n.setLocaleMessage(
resolvedLocale,
loadMessages(resolvedLocale)
);
component.$i18n.locale = resolvedLocale;
} catch (err) {
component.$i18n.setLocaleMessage(localeConfig.fallbackLocale, loadMessages(localeConfig.fallbackLocale));
component.$i18n.setLocaleMessage(
localeConfig.fallbackLocale,
loadMessages(localeConfig.fallbackLocale)
);
component.$i18n.locale = localeConfig.fallbackLocale;
}
}
......@@ -61,13 +61,13 @@ export class Page {
* @returns {Promise<undefined|Page>}
*/
async previous() {
return this._previous && await this._previous.fetch();
return this._previous && (await this._previous.fetch());
}
/** Returns the next page, or undefined if no next page is available.
* @returns {Promise<undefined|Page>}
*/
async next() {
return this._next && await this._next.fetch();
return this._next && (await this._next.fetch());
}
}
......@@ -3,12 +3,22 @@ import Home from '../components/Home';
import CreateCampaign from '../domain/campaigns/CreateCampaign';
import ViewCampaign from '../domain/campaigns/ViewCampaign';
import Login from '../domain/accounts/Login';
import { checkPermissions } from "./http";
import { checkPermissions } from './http';
const routes = [
{ path: '/', component: Home },
{ name: 'create-campaign', path: '/campaigns/new', component: CreateCampaign, meta: { requiresAuth: true } },
{ name: 'view-campaign', path: '/campaigns/:campaignId', component: ViewCampaign, props: true },
{
name: 'create-campaign',
path: '/campaigns/new',
component: CreateCampaign,
meta: { requiresAuth: true }
},
{
name: 'view-campaign',
path: '/campaigns/:campaignId',
component: ViewCampaign,
props: true
},
{ path: '/login', component: Login }
];
......@@ -19,7 +29,7 @@ const router = new Router({
router.beforeEach((to, from, next) => {
if (to.meta && to.meta.requiresAuth) {
checkPermissions(to.path).then(allowed => {
checkPermissions(to.path).then((allowed) => {
if (allowed) {
next();
} else {
......
......@@ -6,7 +6,7 @@ export default {
},
get(key) {
return localStorage.getItem(key);
return localStorage.getItem(key);
},
remove(key) {
......@@ -20,8 +20,11 @@ export default {
restoreState(key, viewModel, defaultState) {
const jsonViewModel = this.get(key);
Object.assign(viewModel, (jsonViewModel && JSON.parse(jsonViewModel)) || defaultState || {});
Object.keys(defaultState).forEach(propertyName => {
Object.assign(
viewModel,
(jsonViewModel && JSON.parse(jsonViewModel)) || defaultState || {}
);
Object.keys(defaultState).forEach((propertyName) => {
if (!viewModel.hasOwnProperty(propertyName)) {
viewModel[propertyName] = defaultState[propertyName];
}
......
......@@ -73,7 +73,7 @@ module.exports = {
new CleanWebpackPlugin({ cleanStaleWebpackAssets: false }),
new VueLoaderPlugin(),
new MiniCssExtractPlugin({
filename: "[name].css"
filename: '[name].css'
}),
// Automatically generates the index file based on a template.
new HtmlWebpackPlugin({
......@@ -96,6 +96,6 @@ module.exports = {
publicPath: '/'
},
resolve: {
extensions: [ '.js', '.vue' ]
extensions: ['.js', '.vue']
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment