Lint single quotes

This commit is contained in:
Tom Russell 2019-05-27 16:31:48 +01:00
parent e540003e2f
commit 907afa29f0
14 changed files with 82 additions and 80 deletions

View File

@ -20,7 +20,8 @@
"rules": {
"no-console": "off",
"strict": ["error", "global"],
"curly": "warn"
"curly": "warn",
"quotes": ["warn", "single"]
},
"plugins": [
"react"

View File

@ -8,6 +8,7 @@
"start": "razzle start",
"build": "razzle build",
"test": "razzle test --env=jsdom",
"lint": "eslint .",
"start:prod": "NODE_ENV=production node build/server.js"
},
"dependencies": {

View File

@ -77,7 +77,7 @@ function queryBuildingsByReference(key, id) {
function getBuildingById(id) {
return db.one(
"SELECT * FROM buildings WHERE building_id = $1",
'SELECT * FROM buildings WHERE building_id = $1',
[id]
).catch(function (error) {
console.error(error);
@ -87,7 +87,7 @@ function getBuildingById(id) {
function getBuildingLikeById(building_id, user_id) {
return db.oneOrNone(
"SELECT true as like FROM building_user_likes WHERE building_id = $1 and user_id = $2 LIMIT 1",
'SELECT true as like FROM building_user_likes WHERE building_id = $1 and user_id = $2 LIMIT 1',
[building_id, user_id]
).then(res => {
return res && res.like
@ -99,7 +99,7 @@ function getBuildingLikeById(building_id, user_id) {
function getBuildingUPRNsById(id) {
return db.any(
"SELECT uprn, parent_uprn FROM building_properties WHERE building_id = $1",
'SELECT uprn, parent_uprn FROM building_properties WHERE building_id = $1',
[id]
).catch(function (error) {
console.error(error);
@ -126,15 +126,15 @@ function saveBuilding(building_id, building, user_id) {
// commit or rollback (repeated-read sufficient? or serializable?)
return db.tx(t => {
return t.one(
`SELECT * FROM buildings WHERE building_id = $1 FOR UPDATE;`,
'SELECT * FROM buildings WHERE building_id = $1 FOR UPDATE;',
[building_id]
).then(old_building => {
const patches = compare(old_building, building, BUILDING_FIELD_WHITELIST);
console.log("Patching", building_id, patches)
console.log('Patching', building_id, patches)
const forward = patches[0];
const reverse = patches[1];
if (Object.keys(forward).length === 0) {
return Promise.reject("No change provided")
return Promise.reject('No change provided')
}
return t.one(
`INSERT INTO logs (
@ -146,7 +146,7 @@ function saveBuilding(building_id, building, user_id) {
[forward, reverse, building_id, user_id]
).then(revision => {
const sets = db.$config.pgp.helpers.sets(forward);
console.log("Setting", building_id, sets)
console.log('Setting', building_id, sets)
return t.one(
`UPDATE
buildings
@ -181,11 +181,11 @@ function likeBuilding(building_id, user_id) {
// commit or rollback (serializable - could be more compact?)
return db.tx({ serializable }, t => {
return t.none(
"INSERT INTO building_user_likes ( building_id, user_id ) VALUES ($1, $2);",
'INSERT INTO building_user_likes ( building_id, user_id ) VALUES ($1, $2);',
[building_id, user_id]
).then(() => {
return t.one(
"SELECT count(*) as likes FROM building_user_likes WHERE building_id = $1;",
'SELECT count(*) as likes FROM building_user_likes WHERE building_id = $1;',
[building_id]
).then(building => {
return t.one(
@ -217,7 +217,7 @@ function likeBuilding(building_id, user_id) {
});
}).catch(function (error) {
console.error(error);
if (error.detail && error.detail.includes("already exists")) {
if (error.detail && error.detail.includes('already exists')) {
// 'already exists' is thrown if user already liked it
return { error: 'It looks like you already like that building!' };
} else {
@ -236,11 +236,11 @@ function unlikeBuilding(building_id, user_id) {
// commit or rollback (serializable - could be more compact?)
return db.tx({ serializable }, t => {
return t.none(
"DELETE FROM building_user_likes WHERE building_id = $1 AND user_id = $2;",
'DELETE FROM building_user_likes WHERE building_id = $1 AND user_id = $2;',
[building_id, user_id]
).then(() => {
return t.one(
"SELECT count(*) as likes FROM building_user_likes WHERE building_id = $1;",
'SELECT count(*) as likes FROM building_user_likes WHERE building_id = $1;',
[building_id]
).then(building => {
return t.one(
@ -272,7 +272,7 @@ function unlikeBuilding(building_id, user_id) {
});
}).catch(function (error) {
console.error(error);
if (error.detail && error.detail.includes("already exists")) {
if (error.detail && error.detail.includes('already exists')) {
// 'already exists' is thrown if user already liked it
return { error: 'It looks like you already like that building!' };
} else {

View File

@ -29,7 +29,7 @@ const BuildingEdit = (props) => {
return (
<Sidebar
key={props.building_id}
title={`You are editing`}
title={'You are editing'}
back={`/edit/${cat}.html`}>
{
CONFIG.map((conf_props) => {
@ -169,8 +169,8 @@ class EditForm extends Component {
const match = this.props.cat === this.props.slug;
const building_like = this.props.building_like;
return (
<section className={(this.props.inactive)? "data-section inactive": "data-section"}>
<header className={`section-header edit ${this.props.slug} ${(match? "active" : "")}`}>
<section className={(this.props.inactive)? 'data-section inactive': 'data-section'}>
<header className={`section-header edit ${this.props.slug} ${(match? 'active' : '')}`}>
<NavLink
to={`/edit/${this.props.slug}/building/${this.props.building_id}.html`}
title={(this.props.inactive)? 'Coming soon… Click the ? for more info.' :
@ -212,28 +212,28 @@ class EditForm extends Component {
{
this.props.fields.map((props) => {
switch (props.type) {
case "text":
case 'text':
return <TextInput {...props} handleChange={this.handleChange}
value={this.state[props.slug]} key={props.slug} />
case "text_list":
case 'text_list':
return <TextListInput {...props} handleChange={this.handleChange}
value={this.state[props.slug]} key={props.slug} />
case "text_long":
case 'text_long':
return <LongTextInput {...props} handleChange={this.handleChange}
value={this.state[props.slug]} key={props.slug} />
case "number":
case 'number':
return <NumberInput {...props} handleChange={this.handleChange}
value={this.state[props.slug]} key={props.slug} />
case "year_estimator":
case 'year_estimator':
return <YearEstimator {...props} handleChange={this.handleChange}
value={this.state[props.slug]} key={props.slug} />
case "text_multi":
case 'text_multi':
return <MultiTextInput {...props} handleChange={this.handleUpdate}
value={this.state[props.slug]} key={props.slug} />
case "checkbox":
case 'checkbox':
return <CheckboxInput {...props} handleChange={this.handleCheck}
value={this.state[props.slug]} key={props.slug} />
case "like":
case 'like':
return <LikeButton {...props} handleLike={this.handleLike}
building_like={building_like}
value={this.state[props.slug]} key={props.slug} />
@ -265,7 +265,7 @@ const TextInput = (props) => (
<Label slug={props.slug} title={props.title} tooltip={props.tooltip} />
<input className="form-control" type="text"
id={props.slug} name={props.slug}
value={props.value || ""}
value={props.value || ''}
maxLength={props.max_length}
disabled={props.disabled}
placeholder={props.placeholder}
@ -282,7 +282,7 @@ const LongTextInput = (props) => (
disabled={props.disabled}
placeholder={props.placeholder}
onChange={props.handleChange}
value={props.value || ""}></textarea>
value={props.value || ''}></textarea>
</Fragment>
)
@ -312,7 +312,7 @@ class MultiTextInput extends Component {
add(event) {
event.preventDefault();
const values = this.getValues().concat("");
const values = this.getValues().concat('');
this.props.handleChange(this.props.slug, values);
}
@ -335,7 +335,7 @@ class MultiTextInput extends Component {
<input className="form-control" type="text"
key={`${this.props.slug}-${i}`} name={`${this.props.slug}-${i}`}
data-index={i}
value={item || ""}
value={item || ''}
placeholder={this.props.placeholder}
disabled={this.props.disabled}
onChange={this.edit}
@ -360,7 +360,7 @@ const TextListInput = (props) => (
<Label slug={props.slug} title={props.title} tooltip={props.tooltip} />
<select className="form-control"
id={props.slug} name={props.slug}
value={props.value || ""}
value={props.value || ''}
disabled={props.disabled}
list={`${props.slug}_suggestions`}
onChange={props.handleChange}>
@ -379,7 +379,7 @@ const NumberInput = (props) => (
<Label slug={props.slug} title={props.title} tooltip={props.tooltip} />
<input className="form-control" type="number" step={props.step}
id={props.slug} name={props.slug}
value={props.value || ""}
value={props.value || ''}
disabled={props.disabled}
onChange={props.handleChange}
/>

View File

@ -24,7 +24,7 @@ const BuildingView = (props) => {
}
const cat = parseCategoryURL(props.match.url);
return (
<Sidebar title={`Data available for this building`} back={`/view/${cat}.html`}>
<Sidebar title={'Data available for this building'} back={`/view/${cat}.html`}>
{
CONFIG.map(section_props => (
<DataSection
@ -35,19 +35,19 @@ const BuildingView = (props) => {
section_props.fields.map(field_props => {
switch (field_props.type) {
case "uprn_list":
case 'uprn_list':
return <UPRNsDataEntry
key={field_props.slug}
title={field_props.title}
value={props.uprns}
tooltip={field_props.tooltip} />
case "text_multi":
case 'text_multi':
return <MultiDataEntry
key={field_props.slug}
title={field_props.title}
value={props[field_props.slug]}
tooltip={field_props.tooltip} />
case "like":
case 'like':
return <LikeDataEntry
key={field_props.slug}
title={field_props.title}
@ -74,8 +74,8 @@ const BuildingView = (props) => {
const DataSection = (props) => {
const match = props.cat === props.slug;
return (
<section id={props.slug} className={(props.inactive)? "data-section inactive": "data-section"}>
<header className={`section-header view ${props.slug} ${(match? "active" : "")}`}>
<section id={props.slug} className={(props.inactive)? 'data-section inactive': 'data-section'}>
<header className={`section-header view ${props.slug} ${(match? 'active' : '')}`}>
<NavLink
to={`/view/${props.slug}/building/${props.building_id}.html`}
title={(props.inactive)? 'Coming soon… Click the ? for more info.' :
@ -120,8 +120,8 @@ const DataEntry = (props) => (
{ props.tooltip? <Tooltip text={ props.tooltip } /> : null }
</dt>
<dd>{
(props.value != null && props.value !== "")?
(typeof(props.value) === "boolean")?
(props.value != null && props.value !== '')?
(typeof(props.value) === 'boolean')?
(props.value)? 'Yes' : 'No'
: props.value
: '\u00A0'}</dd>

View File

@ -5,8 +5,8 @@ import './legend.css';
const LEGEND_CONFIG = {
location: {
title: "Location",
description: "% data collected",
title: 'Location',
description: '% data collected',
elements: [
{ color: '#084081', text: '≥80%' },
{ color: '#0868ac', text: '6080%' },
@ -16,7 +16,7 @@ const LEGEND_CONFIG = {
]
},
age: {
title: "Age",
title: 'Age',
elements: [
{ color: '#f0eaba', text: '≥2000' },
{ color: '#fae269', text: '19802000' },
@ -40,7 +40,7 @@ const LEGEND_CONFIG = {
]
},
size: {
title: "Number of storeys",
title: 'Number of storeys',
elements: [
{ color: '#ffffcc', text: '≥40' },
{ color: '#fed976', text: '2039' },
@ -50,48 +50,48 @@ const LEGEND_CONFIG = {
]
},
like: {
title: "Like Me",
title: 'Like Me',
elements: [
{ color: "#bd0026", text: '👍👍👍 ≥10' },
{ color: "#e31a1c", text: '👍👍 510' },
{ color: "#fc4e2a", text: '👍 4' },
{ color: "#fd8d3c", text: '👍 3' },
{ color: "#feb24c", text: '👍 2' },
{ color: "#fed976", text: '👍 1' },
{ color: '#bd0026', text: '👍👍👍 ≥10' },
{ color: '#e31a1c', text: '👍👍 510' },
{ color: '#fc4e2a', text: '👍 4' },
{ color: '#fd8d3c', text: '👍 3' },
{ color: '#feb24c', text: '👍 2' },
{ color: '#fed976', text: '👍 1' },
]
},
use: {
title: "Use",
title: 'Use',
elements: []
},
ownership: {
title: "Ownership",
title: 'Ownership',
elements: []
},
construction: {
title: "Construction",
title: 'Construction',
elements: []
},
team: {
title: "Team",
title: 'Team',
elements: []
},
sustainability: {
title: "Sustainability",
title: 'Sustainability',
elements: []
},
greenery: {
title: "Greenery",
title: 'Greenery',
elements: []
},
planning: {
title: "Planning",
title: 'Planning',
elements: [
{ color: "#73ebaf", text: 'within conservation area' },
{ color: '#73ebaf', text: 'within conservation area' },
]
},
demolition: {
title: "Demolition",
title: 'Demolition',
elements: []
}
};

View File

@ -112,8 +112,8 @@ class ColouringMap extends Component {
: null;
const base_layer_url = (this.state.theme === 'light')?
`/tiles/base_light/{z}/{x}/{y}.png`
: `/tiles/base_night/{z}/{x}/{y}.png`
'/tiles/base_light/{z}/{x}/{y}.png'
: '/tiles/base_night/{z}/{x}/{y}.png'
return (
<Fragment>

View File

@ -35,8 +35,8 @@ const OverviewSection = (props) => {
const inactive = props.inactive;
return (
<section className={(inactive? "inactive ": "") + "data-section legend"}>
<header className={`section-header ${props.mode} ${props.slug} ${(match? "active" : "")}`}>
<section className={(inactive? 'inactive ': '') + 'data-section legend'}>
<header className={`section-header ${props.mode} ${props.slug} ${(match? 'active' : '')}`}>
<NavLink
to={`/${props.mode}/${props.slug}.html`}
isActive={() => match}

View File

@ -10,7 +10,7 @@ class SearchBox extends Component {
constructor(props) {
super(props);
this.state = {
q: "",
q: '',
results: [],
fetching: false
}
@ -27,7 +27,7 @@ class SearchBox extends Component {
q: e.target.value
});
// If the clear icon has been clicked, clear results list as well
if(e.target.value === "") {
if(e.target.value === '') {
this.clearResults();
}
}
@ -49,7 +49,7 @@ class SearchBox extends Component {
clearQuery(){
this.setState({
q: ""
q: ''
});
}
@ -115,7 +115,7 @@ class SearchBox extends Component {
</ul>
: null;
return (
<div className={`search-box ${this.props.is_building? "building" : ""}`} onKeyDown={this.handleKeyPress}>
<div className={`search-box ${this.props.is_building? 'building' : ''}`} onKeyDown={this.handleKeyPress}>
<form action="/search" method="GET" onSubmit={this.search}
className="form-inline">
<input

View File

@ -22,7 +22,7 @@ class Tooltip extends Component {
render() {
return (
<div className="tooltip-wrap">
<button className={(this.state.active? "active ": "") + "tooltip-hint icon-button"}
<button className={(this.state.active? 'active ': '') + 'tooltip-hint icon-button'}
title={this.props.text}
onClick={this.handleClick}>
Hint

View File

@ -40,7 +40,7 @@ function parseBuildingURL(url) {
*/
function parseCategoryURL(url) {
const default_cat = 'age';
if (url === "/") {
if (url === '/') {
return default_cat
}
const matches = /^\/(view|edit)\/([^/.]+)/.exec(url);

View File

@ -78,7 +78,7 @@ function frontendRoute(req, res) {
const user_id = req.session.user_id;
const building_id = parseBuildingURL(req.url);
const is_building = (typeof (building_id) !== "undefined");
const is_building = (typeof (building_id) !== 'undefined');
if (is_building && isNaN(building_id)) {
context.status = 404;
}
@ -93,7 +93,7 @@ function frontendRoute(req, res) {
const building = values[1];
const uprns = values[2];
const building_like = values[3];
if (is_building && typeof (building) === "undefined") {
if (is_building && typeof (building) === 'undefined') {
context.status = 404
}
data.user = user;
@ -226,7 +226,7 @@ function updateBuilding(req, res, user_id) {
res.send(building)
return
}
if (typeof (building) === "undefined") {
if (typeof (building) === 'undefined') {
res.send({ error: 'Database error' })
return
}
@ -240,7 +240,7 @@ function updateBuilding(req, res, user_id) {
server.get('/building/:building_id/uprns.json', function (req, res) {
const { building_id } = req.params;
getBuildingUPRNsById(building_id).then(function (result) {
if (typeof (result) === "undefined") {
if (typeof (result) === 'undefined') {
res.send({ error: 'Database error' })
return
}
@ -281,7 +281,7 @@ server.route('/building/:building_id/like.json')
res.send(building)
return
}
if (typeof (building) === "undefined") {
if (typeof (building) === 'undefined') {
res.send({ error: 'Database error' })
return
}
@ -295,7 +295,7 @@ server.route('/building/:building_id/like.json')
res.send(building)
return
}
if (typeof (building) === "undefined") {
if (typeof (building) === 'undefined') {
res.send({ error: 'Database error' })
return
}
@ -316,7 +316,7 @@ server.post('/users', function (req, res) {
if (user.email) {
if (user.email != user.confirm_email) {
res.send({ error: "Email did not match confirmation." });
res.send({ error: 'Email did not match confirmation.' });
return
}
} else {
@ -401,7 +401,7 @@ server.get('/search', function (req, res) {
return
}
queryLocation(search_term).then((results) => {
if (typeof (results) === "undefined") {
if (typeof (results) === 'undefined') {
res.send({
error: 'Database error'
})

View File

@ -97,7 +97,7 @@ function remove(tileset, z, x, y) {
if(err){
// pass
} else {
console.log("Expire cache", tileset, z, x, y)
console.log('Expire cache', tileset, z, x, y)
}
resolve()
})

View File

@ -60,7 +60,7 @@ function handle_tile_request(tileset, req, res) {
const int_y = strictParseInt(y);
if (isNaN(int_x) || isNaN(int_y) || isNaN(int_z)) {
console.error("Missing x or y or z")
console.error('Missing x or y or z')
return { error: 'Bad parameter' }
}
@ -189,7 +189,7 @@ function handle_highlight_tile_request(req, res) {
const int_y = strictParseInt(y);
if (isNaN(int_x) || isNaN(int_y) || isNaN(int_z)) {
console.error("Missing x or y or z")
console.error('Missing x or y or z')
return { error: 'Bad parameter' }
}