Skip to content

Commit 6bad31d

Browse files
committed
Update ESLint configuration and fix linting errors in code files
1 parent e09803e commit 6bad31d

25 files changed

Lines changed: 261 additions & 127 deletions

.eslintrc.js

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,12 @@
11
module.exports = {
2-
"env": {
3-
"browser": true,
4-
"es6": true
2+
env: {
3+
es6: true,
4+
node: true,
5+
mocha: true,
56
},
6-
"extends": ["eslint:recommended"],
7-
"parserOptions": {
8-
"sourceType": "module",
9-
"ecmaVersion": 2017
7+
extends: ["gbv"],
8+
parserOptions: {
9+
sourceType: "module",
10+
ecmaVersion: 2020,
1011
},
11-
"rules": {
12-
"indent": [
13-
"error",
14-
2
15-
],
16-
"linebreak-style": [
17-
"error",
18-
"unix"
19-
],
20-
"quotes": [
21-
"error",
22-
"double"
23-
],
24-
"semi": [
25-
"error",
26-
"never"
27-
],
28-
"no-undef": "off",
29-
"no-console": "off"
30-
}
3112
}

config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,22 @@ config.serverVersion = require("./package.json").version
6565
// Concepts (read only)
6666
config.concepts = {
6767
read: {
68-
auth: false
69-
}
68+
auth: false,
69+
},
7070
}
7171
// Mappings (read only by default)
7272
config.mappings = {
7373
read: {
74-
auth: false
74+
auth: false,
7575
},
7676
fromSchemeWhitelist: [
7777
{
78-
uri: "http://bartoc.org/en/node/1940"
79-
}
78+
uri: "http://bartoc.org/en/node/1940",
79+
},
8080
],
8181
toSchemeWhitelist: [],
8282
anonymous: true,
83-
cardinality: "1-to-1"
83+
cardinality: "1-to-1",
8484
}
8585
// Identity requirements
8686
config.identities = null

lib/debug.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ const debug = require("debug")
44
module.exports = {
55
sparql: message => debug("sparql")(message),
66
http: message => debug("http")(message),
7-
query: message => debug("query")(message)
7+
query: message => debug("query")(message),
88
}

lib/mappers.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const wikidata = require("./wikidata")
99
function mapIdentifier (id) {
1010
return {
1111
uri: "http://www.wikidata.org/entity/" + id,
12-
notation: [ id ]
12+
notation: [ id ],
1313
}
1414
}
1515

@@ -27,7 +27,7 @@ function mapSimpleDescriptions (descriptions) {
2727
const scopeNote = languages.reduce((notes, lang) => {
2828
notes[lang] = [ descriptions[lang] ]
2929
return notes
30-
}, { "-": [] }
30+
}, { "-": [] },
3131
)
3232
return { scopeNote }
3333
} else {
@@ -48,11 +48,11 @@ function mapMappingClaims (claims, options = {}) {
4848
list.forEach(mapping => {
4949
mapping.fromScheme = {
5050
uri: wikidata.uri,
51-
notation: wikidata.notation
51+
notation: wikidata.notation,
5252
}
5353
mapping.toScheme = {
5454
uri: scheme.uri,
55-
notation: scheme.notation
55+
notation: scheme.notation,
5656
}
5757
mapping.from = { memberSet: [ ] }
5858
if (from) {
@@ -71,7 +71,9 @@ function mapMappingClaims (claims, options = {}) {
7171
}
7272

7373
function mapSimpleClaims (claims) {
74-
if (!claims) return {}
74+
if (!claims) {
75+
return {}
76+
}
7577

7678
const mediaUrl = media => "http://commons.wikimedia.org/wiki/Special:FilePath/" + encodeURIComponent(media)
7779

@@ -92,7 +94,7 @@ function mapSimpleClaims (claims) {
9294
P576: ["endDate", false],
9395
P625: ["location", false, (coord) => {
9496
return { type: "Point", coordinates: [ coord[1], coord[0] ] } // lon, lat
95-
}]
97+
}],
9698
}
9799

98100
var concept = {}
@@ -101,7 +103,9 @@ function mapSimpleClaims (claims) {
101103
const propertyClaims = claims[property]
102104

103105
var mapping = mappings[property]
104-
if (!mapping) continue
106+
if (!mapping) {
107+
continue
108+
}
105109

106110
const field = mapping.shift()
107111

@@ -127,39 +131,41 @@ function mapSimpleClaims (claims) {
127131
}
128132

129133
function mapSimpleSitelinks (sitelinks) {
130-
if (!sitelinks) return {}
134+
if (!sitelinks) {
135+
return {}
136+
}
131137

132138
// TODO: get sitelinks-matrix and filter by language?
133139
return {
134140
occurrences: [
135141
{
136-
database: { "uri": "http://www.wikidata.org/entity/Q2013" },
142+
database: { uri: "http://www.wikidata.org/entity/Q2013" },
137143
relation: "http://schema.org/about",
138-
count: Object.keys(sitelinks).length
139-
}
144+
count: Object.keys(sitelinks).length,
145+
},
140146
],
141147
subjectOf: Object.keys(sitelinks).map(site => {
142148
try {
143149
return {
144-
url: wdk.getSitelinkUrl(site, sitelinks[site])
150+
url: wdk.getSitelinkUrl(site, sitelinks[site]),
145151
}
146152
} catch (e) {
147153
// just ignore unkown sites
148154

149155
}
150-
}).filter(site => site)
156+
}).filter(site => site),
151157
}
152158
}
153159

154160
function mapInfo (entity) {
155161
const type = [
156162
"http://www.w3.org/2004/02/skos/core#Concept",
157-
entityTypes[entity.type]
163+
entityTypes[entity.type],
158164
]
159165
return {
160166
modified: entity.modified,
161167
type,
162-
inScheme: [{ uri: wikidata.uri }]
168+
inScheme: [{ uri: wikidata.uri }],
163169
}
164170
}
165171

@@ -171,7 +177,7 @@ function mapSimpleEntity (entity) {
171177
mapSimpleDescriptions(entity.descriptions),
172178
mapSimpleClaims(entity.claims),
173179
mapSimpleSitelinks(entity.sitelinks),
174-
mapInfo(entity)
180+
mapInfo(entity),
175181
)
176182
}
177183

@@ -194,5 +200,5 @@ module.exports = {
194200
mapSitelinks: sitelinks => mapSimpleSitelinks(wdk.simplify.sitelinks(sitelinks)),
195201
mapEntity: entity => mapSimpleEntity(wdk.simplify.entity(entity)),
196202
mapInfo,
197-
mapMappingClaims
203+
mapMappingClaims,
198204
}

lib/mapping-schemes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ module.exports = {
2323
const cachedSchemes = `${cache}/mapping-schemes.ndjson`
2424
const assetsSchemes = `${assets}/mapping-schemes.ndjson`
2525
return ndjson.read( fs.existsSync(cachedSchemes) ? cachedSchemes : assetsSchemes )
26-
}
26+
},
2727

2828
}

lib/ndjson.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ module.exports = {
88
const stream = file ? fs.createWriteStream(file) : process.stdout
99
const objects = Array.isArray(data) ? data : [data]
1010
objects.forEach(obj => stream.write(JSON.stringify(obj) + "\n"))
11-
}
11+
},
1212
}

lib/queries/get-backlinks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function getBacklinks (uris, languages, properties) {
2222
entities[uri] = {
2323
uri,
2424
prefLabel: (languages && languages.length ? { "-": "?" } : { }),
25-
notation: [uri.split("/").pop()]
25+
notation: [uri.split("/").pop()],
2626
}
2727
}
2828

lib/queries/get-concepts.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ const { mapEntity } = require("../mappers")
77

88
async function getConcepts (query) {
99
const concepts = detectWikidataConcepts(query.uri)
10-
if (!concepts.length) return []
10+
if (!concepts.length) {
11+
return []
12+
}
1113

1214
const languages = selectedLanguages(query)
1315
const props = ["info", "sitelinks", "labels", "aliases", "descriptions", "claims"]
@@ -18,9 +20,13 @@ async function getConcepts (query) {
1820
.then(entities => Object.values(entities).filter(e => !("missing" in e)))
1921
.then(entities => entities.map(mapEntity))
2022
.then(entities => {
21-
if (!entities.length) return []
23+
if (!entities.length) {
24+
return []
25+
}
2226
const index = {}
23-
entities.forEach(e => { index[e.uri] = e })
27+
entities.forEach(e => {
28+
index[e.uri] = e
29+
})
2430
const rels = ["P361", "P31", "P279", "P131"]
2531
return getBacklinks(Object.keys(index), languages, rels)
2632
.then(backlinks => {

lib/queries/get-mapping-list.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ LIMIT ${limit} OFFSET ${offset}`
4242
.then(rows => rows.map(row => {
4343

4444
const to = toScheme.conceptFromNotation(row.value.value)
45-
if (!to) return // malformed notation in Wikidata
45+
if (!to) {
46+
return
47+
} // malformed notation in Wikidata
4648

4749
var type
4850
if (row.mappingType) {
@@ -52,23 +54,23 @@ LIMIT ${limit} OFFSET ${offset}`
5254
type = "http://www.w3.org/2004/02/skos/core#mappingRelation"
5355
}
5456

55-
return mapping = {
57+
return {
5658
uri: row.statement.value,
5759
from: {
5860
memberSet: [ {
5961
uri: row.item.value,
60-
} ]
62+
} ],
6163
},
6264
to: { memberSet: [ to ] },
6365
fromScheme: {
6466
uri: "http://bartoc.org/en/node/1940",
65-
notation: ["WD"]
67+
notation: ["WD"],
6668
},
6769
toScheme: {
6870
uri: toScheme.uri,
69-
notation: toScheme.notation
71+
notation: toScheme.notation,
7072
},
71-
type: [ type ]
73+
type: [ type ],
7274
}
7375
}).filter(Boolean))
7476

lib/queries/get-mapping-schemes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function getMappingSchemes () {
6161
// we cannot escape all special character but spaces are needed
6262
const escapedNotationPattern = notationPattern.split(" ").join("%20")
6363
const uriPattern = "^" + template.split("$1").map(s =>
64-
s.replace(/[\\^$*+?.()|[\]{}]/g, "\\$&")
64+
s.replace(/[\\^$*+?.()|[\]{}]/g, "\\$&"),
6565
).join("(" + escapedNotationPattern + ")") + "$"
6666

6767
const scheme = {
@@ -70,7 +70,7 @@ function getMappingSchemes () {
7070
notationPattern,
7171
uriPattern,
7272
namespace: template.replace(/\$1.*/, ""),
73-
PROPERTY: row.property.value.split("/").pop()
73+
PROPERTY: row.property.value.split("/").pop(),
7474
}
7575
if (row.extent) {
7676
scheme.extent = row.extent.value

0 commit comments

Comments
 (0)