Skip to content

Commit

Permalink
Conform to linter
Browse files Browse the repository at this point in the history
  • Loading branch information
jdesboeufs committed Feb 22, 2022
1 parent aaf5984 commit 343fe6c
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 25 deletions.
4 changes: 2 additions & 2 deletions build/add-list.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const {join} = require('path')
const path = require('path')
const {pick} = require('lodash')
const readCsv = require('./read-csv')

const ADD_LIST_PATH = join(__dirname, '..', 'add-list.csv')
const ADD_LIST_PATH = path.join(__dirname, '..', 'add-list.csv')

async function loadAddList() {
const rows = await readCsv(ADD_LIST_PATH)
Expand Down
4 changes: 2 additions & 2 deletions build/communes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const arrondissementsMunicipaux = require('@etalab/decoupage-administratif/data/

function connectGraph(historiqueCommunes) {
const byId = keyBy(historiqueCommunes, 'id')
historiqueCommunes.forEach(h => {
for (const h of historiqueCommunes) {
if (h.successeur) {
h.successeur = byId[h.successeur]
}
Expand All @@ -22,7 +22,7 @@ function connectGraph(historiqueCommunes) {
if (h.membres) {
h.membres = h.membres.map(m => byId[m])
}
})
}
}

connectGraph(historiqueCommunes)
Expand Down
8 changes: 3 additions & 5 deletions build/extract-fimoct.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ function eachLine(line, ignoreList, cb) {
const borneInferieureRepetition = line.substr(107, 1).trim()
const indicateurAdressage = line.substr(115, 1).trim()

if (!codePostal.match(/(\d{5})/)) return cb()
if (!/(\d{5})/.test(codePostal)) return cb()
if (codeCommune.startsWith('B')) return cb() // On ignore les codes postaux de pays étrangers
if (codeCommune === '06900') return cb() // On ignore Monaco
if (codeCommune === '97123') return cb() // On ignore Saint-Barthelemy
if (codeCommune === '97127') return cb() // On ignore Saint-Martin

// On ignore tous les couples codeCommune/codePostal renseignés dans le fichier CSV ignore-list.csv
if (codeCommune in ignoreList) {
if (ignoreList[codeCommune].some(item => item.codePostal === codePostal)) {
return cb()
}
if (codeCommune in ignoreList && ignoreList[codeCommune].some(item => item.codePostal === codePostal)) {
return cb()
}

const result = {
Expand Down
4 changes: 2 additions & 2 deletions build/ignore-list.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const {join} = require('path')
const path = require('path')
const {groupBy} = require('lodash')
const readCsv = require('./read-csv')

const IGNORE_LIST_PATH = join(__dirname, '..', 'ignore-list.csv')
const IGNORE_LIST_PATH = path.join(__dirname, '..', 'ignore-list.csv')

async function loadIgnoreList() {
const rows = await readCsv(IGNORE_LIST_PATH)
Expand Down
10 changes: 5 additions & 5 deletions build/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint unicorn/no-process-exit: off */
#!/usr/bin/env node
const fs = require('fs')
const {join} = require('path')
const path = require('path')
const {promisify} = require('util')
const {chain, pick} = require('lodash')
const {getLatestFIMOCTFileBuffer} = require('./download-fimoct')
Expand Down Expand Up @@ -57,10 +57,10 @@ function expandWithDefault(codesPostaux) {
async function main() {
const buffer = await getLatestFIMOCTFileBuffer()
const codesPostaux = expandWithDefault(await extractFromFIMOCT(buffer))
codesPostaux.forEach(item => expandWithCommune(item))
await writeAsJSONFile(join(__dirname, '..', 'codes-postaux-full.json'), codesPostaux)
for (const item of codesPostaux) expandWithCommune(item)
await writeAsJSONFile(path.join(__dirname, '..', 'codes-postaux-full.json'), codesPostaux)
const codesPostauxCompact = buildCompact(codesPostaux)
await writeAsJSONFile(join(__dirname, '..', 'codes-postaux.json'), codesPostauxCompact)
await writeAsJSONFile(path.join(__dirname, '..', 'codes-postaux.json'), codesPostauxCompact)
}

main().catch(error => {
Expand Down
8 changes: 3 additions & 5 deletions full.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,9 @@ function findCodePostal(codeCommune, idVoie, numero, repetition) {
const entries = voiesIndex[idVoieMatch]
if (entries.length === 1) return formatResult(entries[0])
const parsedNumero = Number.parseInt(numero, 10)
const candidate = entries.find(entry => {
return pariteOK(parsedNumero, entry.codeParite) &&
superieurBorneInf(parsedNumero, repetition, entry.borneInferieure) &&
inferieurBorneSup(parsedNumero, repetition, entry.borneSuperieure)
})
const candidate = entries.find(entry => pariteOK(parsedNumero, entry.codeParite)
&& superieurBorneInf(parsedNumero, repetition, entry.borneInferieure)
&& inferieurBorneSup(parsedNumero, repetition, entry.borneSuperieure))
if (candidate) return formatResult(candidate)
}

Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const index = {}

require('./codes-postaux.json').forEach(entry => {
for (const entry of require('./codes-postaux.json')) {
if (!(entry.codePostal in index)) {
index[entry.codePostal] = []
}

index[entry.codePostal].push(entry)
})
}

exports.find = function (postalCode) {
return index[postalCode] || []
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"comma-dangle": ["error", "never"],
"unicorn/prefer-module": "off",
"unicorn/prefer-string-slice": "off",
"import/extensions": "off"
"import/extensions": "off",
"node/prefer-global/process": "off"

}
},
Expand Down
2 changes: 1 addition & 1 deletion test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const test = require('ava')
const codesPostaux = require('..')

test('75002', t => {
const communes = codesPostaux.find(75002)
const communes = codesPostaux.find(75_002)
t.is(communes.length, 1)
const [commune] = communes
t.is(commune.codePostal, '75002')
Expand Down

0 comments on commit 343fe6c

Please sign in to comment.