Skip to content

Commit

Permalink
Add prefer-template rule
Browse files Browse the repository at this point in the history
  • Loading branch information
atrovato committed Nov 29, 2020
1 parent f875a24 commit fdce47e
Show file tree
Hide file tree
Showing 24 changed files with 63 additions and 45 deletions.
4 changes: 3 additions & 1 deletion front/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"preact-i18n/no-missing-template-field": "error",
"preact-i18n/no-text-as-attribute": "error",
"preact-i18n/no-text-as-children": "error",
"preact-i18n/no-unknown-key": "error"
"preact-i18n/no-unknown-key": "error",
"no-useless-concat": "error",
"prefer-template": "error"
},
"plugins": ["json", "preact-i18n"],
"parserOptions": {
Expand Down
7 changes: 3 additions & 4 deletions front/src/components/boxs/device-in-room/RoomCard.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import cx from 'classnames';

import DeviceRow from './DeviceRow';

const RoomCard = ({ children, ...props }) => {
Expand All @@ -6,10 +8,7 @@ const RoomCard = ({ children, ...props }) => {
}

return (
<div
class={'card ' + (props.room.collapsed ? ' card-collapsed' : '')}
style="display: inline-block; min-width: 300px"
>
<div class={cx('card', { 'card-collapsed': props.room.collapsed })} style="display: inline-block; min-width: 300px">
<div class="card-header">
<h3 class="card-title">{props.room.name}</h3>
<div class="card-options">
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/boxs/weather/EditWeatherBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const EditWeatherBox = ({ children, ...props }) => (
<div>
{Object.keys(GetWeatherModes).map(key => {
const mode = GetWeatherModes[key];
const label = 'dashboard.boxes.weather.displayModes.' + mode;
const label = `dashboard.boxes.weather.displayModes.${mode}`;
return (
<div className="form-check">
<input
Expand Down
12 changes: 7 additions & 5 deletions front/src/components/boxs/weather/WeatherBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Component } from 'preact';
import { connect } from 'unistore/preact';
import { Text } from 'preact-i18n';
import { Link } from 'preact-router/match';
import cx from 'classnames';

import actions from '../../../actions/dashboard/boxes/weather';
import {
RequestStatus,
Expand Down Expand Up @@ -104,7 +106,7 @@ const WeatherBox = ({ children, ...props }) => (
color: '#76838f'
}}
>
{props.datetimeBeautiful + ' - ' + props.houseName}
{`${props.datetimeBeautiful} - ${props.houseName}`}
</div>
<div class="row">
<div class="col-9">
Expand Down Expand Up @@ -134,7 +136,7 @@ const WeatherBox = ({ children, ...props }) => (
}}
>
<i
className={'fe ' + props.weather_icon}
className={cx('fe', props.weather_icon)}
style={{
fontSize: '50px'
}}
Expand Down Expand Up @@ -244,10 +246,10 @@ class WeatherBoxComponent extends Component {
return (
<div style={Object.assign({ width: '10%', margin: '0.25em 1.25%' })}>
<p style={{ margin: 'auto', textAlign: 'center', fontSize: '10px', color: 'grey' }}>
{hour.datetime_beautiful + 'h'}
{`${hour.datetime_beautiful}h`}
</p>
<p style={{ margin: 'auto', textAlign: 'center' }}>
<i className={'fe ' + hour.weather_icon} style={{ fontSize: '20px' }} />
<i className={cx('fe', hour.weather_icon)} style={{ fontSize: '20px' }} />
</p>
<p style={{ margin: 'auto', textAlign: 'center', fontSize: '12px' }}>
<Text id="global.degreeValue" fields={{ value: hour.temperature }} />
Expand All @@ -267,7 +269,7 @@ class WeatherBoxComponent extends Component {
<div className="row" style={{ marginTop: '0.5em' }}>
<div className="col-5">{day.datetime_beautiful}</div>
<div className="col-3">
<i className={'fe ' + day.weather_icon} style={{ fontSize: '20px' }} />
<i className={cx('fe', day.weather_icon)} style={{ fontSize: '20px' }} />
</div>
<div className="col-4" style={{ textAlign: 'right' }}>
<Text
Expand Down
23 changes: 15 additions & 8 deletions front/src/components/header/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Text, Localizer } from 'preact-i18n';
import classnames from 'classnames';
import cx from 'classnames';
import { Link } from 'preact-router/match';
import { isUrlInArray } from '../../utils/url';

Expand Down Expand Up @@ -42,7 +42,7 @@ const Header = ({ ...props }) => {
</span>
</a>
<div class="d-flex order-lg-2 ml-auto">
<div class={'dropdown' + (props.showDropDown && ' show')}>
<div class={cx('dropdown', { show: props.showDropDown })}>
<a onClick={props.toggleDropDown} class="nav-link pr-0 leading-none" data-toggle="dropdown">
<span class="avatar" style={`background-image: url(${props.profilePicture})`} />
<span class="ml-2 d-none d-lg-block">
Expand All @@ -53,7 +53,11 @@ const Header = ({ ...props }) => {
</small>
</span>
</a>
<div class={'dropdown-menu dropdown-menu-right dropdown-menu-arrow' + (props.showDropDown && ' show')}>
<div
class={cx('dropdown-menu', 'dropdown-menu-right', 'dropdown-menu-arrow', {
show: props.showDropDown
})}
>
<a class="dropdown-item" href="/dashboard/profile">
<i class="dropdown-icon fe fe-user" /> <Text id="header.profile" />
</a>
Expand Down Expand Up @@ -86,15 +90,18 @@ const Header = ({ ...props }) => {
</div>
</div>
</div>
<div class={'header collapse d-lg-flex p-0 ' + (props.showCollapsedMenu && ' show')} id="headerMenuCollapse">
<div
class={cx('header', 'collapse', 'd-lg-flex', 'p-0', { show: props.showCollapsedMenu })}
id="headerMenuCollapse"
>
<div class="container">
<div class="row align-items-center">
<div class="col-lg order-lg-first">
<ul class="nav nav-tabs border-0 flex-column flex-lg-row">
<li class="nav-item">
<Link
href="/dashboard"
class={classnames('nav-link', {
class={cx('nav-link', {
active: props.currentUrl === '/dashboard'
})}
>
Expand All @@ -104,7 +111,7 @@ const Header = ({ ...props }) => {
<li class="nav-item">
<Link
href="/dashboard/chat"
class={classnames('nav-link', {
class={cx('nav-link', {
active: props.currentUrl === '/dashboard/chat'
})}
>
Expand All @@ -122,7 +129,7 @@ const Header = ({ ...props }) => {
<li class="nav-item">
<Link
href="/dashboard/calendar"
class={classnames('nav-link', {
class={cx('nav-link', {
active: props.currentUrl === '/dashboard/calendar'
})}
>
Expand All @@ -133,7 +140,7 @@ const Header = ({ ...props }) => {
<Link
activeClassName="active"
href="/dashboard/maps"
class={classnames('nav-link', {
class={cx('nav-link', {
active: props.currentUrl === '/dashboard/maps'
})}
>
Expand Down
2 changes: 1 addition & 1 deletion front/src/routes/dashboard/EditAddBoxButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const EditAddBoxButton = ({ children, ...props }) => (
</option>
{DASHBOARD_BOX_TYPE_LIST.map(dashboardBoxType => (
<option value={dashboardBoxType}>
<Text id={'dashboard.boxTitle.' + dashboardBoxType} />
<Text id={`dashboard.boxTitle.${dashboardBoxType}`} />
</option>
))}
</select>
Expand Down
2 changes: 1 addition & 1 deletion front/src/routes/gateway-confirm-email/ConfirmEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const ConfirmEmail = ({ children, ...props }) => (
</div>

<div class="form-footer">
<a href={'/login?email=' + props.email} class="btn btn-primary btn-block">
<a href={`/login?email=${props.email}`} class="btn btn-primary btn-block">
<Text id="forgotPassword.signIn" />
</a>
</div>
Expand Down
5 changes: 3 additions & 2 deletions front/src/routes/gateway-reset-password/ResetPasswordForm.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Text, Localizer } from 'preact-i18n';
import cx from 'classnames';

const ResetPassworFrom = ({ children, ...props }) => (
<form onSubmit={props.resetPassword} className="card">
Expand Down Expand Up @@ -28,7 +29,7 @@ const ResetPassworFrom = ({ children, ...props }) => (
<Localizer>
<input
type="password"
className={'form-control ' + (props.passwordError ? 'is-invalid' : '')}
className={cx('form-control', { 'is-invalid': props.passwordError })}
placeholder={<Text id="gatewayResetPassword.passwordPlaceholder" />}
value={props.password}
onInput={props.updatePassword}
Expand All @@ -45,7 +46,7 @@ const ResetPassworFrom = ({ children, ...props }) => (
<Localizer>
<input
type="password"
className={'form-control ' + (props.passwordError ? 'is-invalid' : '')}
className={cx('form-control', { 'is-invalid': props.passwordError })}
placeholder={<Text id="gatewayResetPassword.passwordPlaceholder" />}
value={props.passwordRepeat}
onInput={props.updatePasswordRepeat}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function createActions(store) {
store.setState(newState);
},
async deleteDevice(state, device, index) {
await state.httpClient.delete('/api/v1/device/' + device.selector);
await state.httpClient.delete(`/api/v1/device/${device.selector}`);
const newState = update(state, {
bluetoothDevices: {
$splice: [[index, 1]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class BluetoothPeripheral extends Component {
/>
<div class="form-group">
{bluetoothDevice && (
<Link href={'/dashboard/integration/device/bluetooth/setup/' + peripheral.selector}>
<Link href={`/dashboard/integration/device/bluetooth/setup/${peripheral.selector}`}>
{!peripheralService && (
<button class="btn btn-success">
<Text id="integration.bluetooth.setup.createDeviceInGladys" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const GITHUB_BASE_URL = 'https://github.com/GladysAssistant/Gladys/issues/new';

const createGithubUrl = device => {
const title = encodeURIComponent(`Philips Hue: Add device ${device.model}`);
const body = encodeURIComponent('```\n' + JSON.stringify(device, null, 2) + '\n```');
const body = encodeURIComponent(`\`\`\`\n${JSON.stringify(device, null, 2)}\n\`\`\``);
return `${GITHUB_BASE_URL}?title=${title}&body=${body}`;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function createActions(store) {
store.setState(newState);
},
async deleteDevice(state, device, index) {
await state.httpClient.delete('/api/v1/device/' + device.selector);
await state.httpClient.delete(`/api/v1/device/${device.selector}`);
const newState = update(state, {
philipsHueDevices: {
$splice: [[index, 1]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const actions = store => ({
philipsHueDeleteDeviceStatus: RequestStatus.Getting
});
try {
await state.httpClient.delete('/api/v1/device/' + device.selector);
await state.httpClient.delete(`/api/v1/device/${device.selector}`);
const newState = update(state, {
philipsHueBridgesDevices: {
$splice: [[index, 1]]
Expand Down
2 changes: 1 addition & 1 deletion front/src/routes/integration/all/xiaomi/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function createActions(store) {
await state.httpClient.post('/api/v1/device', device);
},
async deleteDevice(state, device, index) {
await state.httpClient.delete('/api/v1/device/' + device.selector);
await state.httpClient.delete(`/api/v1/device/${device.selector}`);
const newState = update(state, {
xiaomiDevices: {
$splice: [[index, 1]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function createActions(store) {
store.setState(newState);
},
async deleteDevice(state, device, index) {
await state.httpClient.delete('/api/v1/device/' + device.selector);
await state.httpClient.delete(`/api/v1/device/${device.selector}`);
const newState = update(state, {
zwaveDevices: {
$splice: [[index, 1]]
Expand Down
2 changes: 1 addition & 1 deletion front/src/routes/integration/all/zwave/setup-page/Node.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const createGithubUrl = node => {
classes: Object.keys(rawZwaveNode.classes)
};
const title = encodeURIComponent(`Z-Wave: Handle device "${rawZwaveNode.manufacturer} ${rawZwaveNode.product}"`);
const body = encodeURIComponent('```\n' + JSON.stringify(deviceToSend, null, 2) + '\n```');
const body = encodeURIComponent(`\`\`\`\n${JSON.stringify(deviceToSend, null, 2)}\n\`\`\``);
return `${GITHUB_BASE_URL}?title=${title}&body=${body}`;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Text, Localizer, MarkupText } from 'preact-i18n';
import cx from 'classnames';

import OpenApiKey from './OpenApiKey';

Expand Down Expand Up @@ -44,7 +45,7 @@ const OpenApi = ({ children, ...props }) => (
<Localizer>
<input
type="text"
class={'form-control ' + (props.missingNewOpenApiName ? 'is-invalid' : '')}
class={cx('form-control', { 'is-invalid': props.missingNewOpenApiName })}
value={props.newApiKeyName}
onChange={props.updateNewApiKeyName}
placeholder={<Text id="gatewayOpenApi.keyName" />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const UserRow = ({ children, ...props }) => {
<td class="w-1">
<span
class="avatar"
style={'background-image: url(' + (props.user.profile_url || '/assets/images/undraw_profile_pic.svg') + ')'}
style={`background-image: url(${props.user.profile_url || '/assets/images/undraw_profile_pic.svg'}')`}
/>
</td>
<td>
Expand Down
7 changes: 4 additions & 3 deletions front/src/routes/signup-gateway/SignupForm.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Text, Localizer } from 'preact-i18n';
import cx from 'classnames';

const SignupForm = ({ children, ...props }) => (
<form onSubmit={props.validateForm} className="card">
Expand Down Expand Up @@ -44,7 +45,7 @@ const SignupForm = ({ children, ...props }) => (
<Localizer>
<input
type="text"
className={'form-control ' + (props.fieldsErrored.includes('name') ? 'is-invalid' : '')}
className={cx('form-control', { 'is-invalid': props.fieldsErrored.includes('name') })}
placeholder={<Text id="gatewaySignUp.usernamePlaceholder" />}
value={props.name}
onInput={props.updateName}
Expand All @@ -61,7 +62,7 @@ const SignupForm = ({ children, ...props }) => (
<Localizer>
<input
type="email"
className={'form-control ' + (props.fieldsErrored.includes('email') ? 'is-invalid' : '')}
className={cx('form-control', { 'is-invalid': props.fieldsErrored.includes('email') })}
placeholder={<Text id="gatewaySignUp.emailPlaceholder" />}
value={props.email}
disabled={props.token && 'disabled'}
Expand All @@ -79,7 +80,7 @@ const SignupForm = ({ children, ...props }) => (
<Localizer>
<input
type="password"
className={'form-control ' + (props.fieldsErrored.includes('password') ? 'is-invalid' : '')}
className={cx('form-control', { 'is-invalid': props.fieldsErrored.includes('password') })}
placeholder={<Text id="gatewaySignUp.passwordPlaceholder" />}
value={props.password}
onInput={props.updatePassword}
Expand Down
7 changes: 4 additions & 3 deletions front/src/routes/signup-gateway/SignupGeneratingKeys.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Text, MarkupText } from 'preact-i18n';
import style from './spinner.css';
import cx from 'classnames';

const SignupGeneratingKeys = ({ children, ...props }) => (
<div onSubmit={props.validateForm} className="card" style={{ height: '250px' }}>
Expand All @@ -13,11 +14,11 @@ const SignupGeneratingKeys = ({ children, ...props }) => (
</p>
)}
</div>
{!props.signupCompleted && <div class={style.spWave + ' ' + style.sp} />}
{!props.signupCompleted && <div class={cx(style.spWave, style.sp)} />}

{props.signupCompleted && (
<div class={style['circle-loader'] + ' ' + style['load-complete']}>
<div class={style.checkmark + ' ' + style.draw} />
<div class={cx(style['circle-loader'], style['load-complete'])}>
<div class={cx(style.checkmark, style.draw)} />
</div>
)}
<div />
Expand Down
5 changes: 3 additions & 2 deletions front/src/routes/signup/1-welcome/WelcomeTab.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import style from '../style.css';
import { Text, MarkupText } from 'preact-i18n';
import { Link } from 'preact-router/match';
import cx from 'classnames';

const margin70px = {
marginTop: '70px'
Expand All @@ -9,8 +10,8 @@ const margin20px = {
marginTop: '20px'
};

const WelcomeStep = ({ children, ...props }) => (
<div class={'row ' + style.equal}>
const WelcomeStep = () => (
<div class={cx('row', style.equal)}>
<div class="col-lg-6">
<h2>
<Text id="signup.welcome.title" />
Expand Down
5 changes: 3 additions & 2 deletions front/src/routes/signup/5-success/SuccessTab.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Text, MarkupText } from 'preact-i18n';
import style from '../style.css';
import { Link } from 'preact-router/match';
import cx from 'classnames';

const ConfigureHouseTab = ({ children, ...props }) => (
const ConfigureHouseTab = () => (
<div class="card">
<div class="card-body">
<div class={'row ' + style.equal}>
<div class={cx('row', style.equal)}>
<div class="col-md">
<img src="/assets/images/pierre-gilles-bali.jpg" />
</div>
Expand Down
2 changes: 1 addition & 1 deletion front/src/utils/bytesFormat.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function bytesFormatter(size) {
const i = size === 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
return `${(size / Math.pow(1024, i)).toFixed(2) * 1} ${['B', 'kB', 'MB', 'GB', 'TB'][i]}`;
}

export { bytesFormatter };
Loading

0 comments on commit fdce47e

Please sign in to comment.