Skip to content

Commit 75a5c06

Browse files
authored
chore: lint with @medic/eslint-config (#662)
* core: uplift dependencies * Bump eslint-webpack-plugin * Bump googleapis * Bump json2csv * Bump mocha * Bump sinon * Bump uuid * Clean up and add dependabot * Fix dependabot.yml indentation * Run auto-fixes * Manually fix line wrapping * Try setting root to true in skeleton eslint * Fix up linting for e2e tests * Fix sonar * Remove unneeded dep from e2e tests * Fix linting in skeleton files
1 parent 1b9bb65 commit 75a5c06

File tree

108 files changed

+1310
-786
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+1310
-786
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
},
66
"extends": [
77
"eslint:recommended",
8-
"plugin:n/recommended"
8+
"plugin:n/recommended",
9+
"@medic"
910
],
1011
"parserOptions": {
1112
"ecmaVersion": 2022

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"devDependencies": {
7575
"@commitlint/cli": "^19.7.1",
7676
"@commitlint/config-conventional": "^19.7.1",
77+
"@medic/eslint-config": "^1.1.0",
7778
"@semantic-release/changelog": "^6.0.3",
7879
"@semantic-release/git": "^10.0.1",
7980
"body-parser": "^1.20.3",

src/bin/shell-completion.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
/* eslint-disable no-console */
44

55
const options = [
6-
'--instance', '--local', '--url', '--user',
7-
'--help', '--shell-completion', '--supported-actions',
8-
'--version', '--accept-self-signed-certs', '--skip-dependency-check',
9-
'--skip-git-check', '--skip-translation-check', '--force',
10-
...require('../cli/supported-actions'),
6+
'--instance', '--local', '--url', '--user',
7+
'--help', '--shell-completion', '--supported-actions',
8+
'--version', '--accept-self-signed-certs', '--skip-dependency-check',
9+
'--skip-git-check', '--skip-translation-check', '--force',
10+
...require('../cli/supported-actions'),
1111
];
1212

1313
console.log(...options);

src/cli/supported-actions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fs = require('fs');
22

33
const actions = fs.readdirSync(`${__dirname}/../fn`)
4-
.filter(name => name.endsWith('.js'))
5-
.map(name => name.substring(0, name.length - 3));
4+
.filter(name => name.endsWith('.js'))
5+
.map(name => name.substring(0, name.length - 3));
66

77
module.exports = actions;

src/cli/usage.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const supportedActions = require('./supported-actions');
22

33
module.exports = () => {
4+
/* eslint-disable max-len */
45
console.log(`
56
${bold('NAME')}
67
cht - Configure your CHT instances
@@ -69,6 +70,7 @@ ${bold('OPTIONS')}
6970
--force
7071
CAN BE DANGEROUS! Passes yes to all commands and any where that would prompt to overwrite changes will overwrite automatically.
7172
`);
73+
/* eslint-enable max-len */
7274
};
7375

7476
const bold = text => `\x1b[1m${text}\x1b[0m`;

src/fn/backup-all-forms.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ module.exports = {
3434
return formsList(db)
3535
.then(res => res.rows)
3636
.then(forms => Promise.all(forms.map(backup)));
37-
}
37+
}
3838
};

src/fn/compile-app-settings.js

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ const JSON_FILE_MATCHER = /^(.+)(\.json)$/;
1616
const configFileMatcher = (fileName) => {
1717
const jsFileMatchResult = fileName.match(JS_FILE_MATCHER);
1818
// the first element is always the whole matched string, then our first file name group
19-
if (jsFileMatchResult) return jsFileMatchResult[1];
19+
if (jsFileMatchResult) {
20+
return jsFileMatchResult[1];
21+
}
2022

2123
const jsonFileMatchResult = fileName.match(JSON_FILE_MATCHER);
22-
if (jsonFileMatchResult) return jsonFileMatchResult[1];
24+
if (jsonFileMatchResult) {
25+
return jsonFileMatchResult[1];
26+
}
2327

2428
return null;
2529
};
@@ -48,7 +52,9 @@ const compileAppSettingsForProject = async (projectDir, options) => {
4852
const oldTaskSchedulesPath = path.join(projectDir, 'tasks.json');
4953
if (fs.exists(oldTaskSchedulesPath)) {
5054
if (fs.exists(taskSchedulesPath)) {
51-
throw new Error(`You have both ${taskSchedulesPath} and ${oldTaskSchedulesPath}. Please remove one to continue!`);
55+
throw new Error(
56+
`You have both ${taskSchedulesPath} and ${oldTaskSchedulesPath}. Please remove one to continue!`
57+
);
5258
}
5359
warn(`tasks.json file is deprecated. Please rename ${oldTaskSchedulesPath} to ${taskSchedulesPath}`);
5460
taskSchedulesPath = oldTaskSchedulesPath;
@@ -66,7 +72,10 @@ const compileAppSettingsForProject = async (projectDir, options) => {
6672
}
6773

6874
if (!fs.exists(baseSettingsPath) && !fs.exists(appSettingsPath)) {
69-
throw new Error('No configuration defined please create a base_settings.json file in app_settings folder with the desired configuration');
75+
throw new Error(
76+
'No configuration defined please create a base_settings.json file in app_settings folder ' +
77+
'with the desired configuration'
78+
);
7079
}
7180
if (fs.exists(baseSettingsPath)) {
7281
// using modular config so should override anything already defined in app_settings.json
@@ -105,8 +114,10 @@ const compileAppSettingsForProject = async (projectDir, options) => {
105114
appSettings.assetlinks = assetlinks;
106115
}
107116
} else {
108-
warn(`app_settings.json file should not be edited directly.
109-
Please create a base_settings.json file in app_settings folder and move any manually defined configurations there.`);
117+
warn(
118+
`app_settings.json file should not be edited directly.
119+
Please create a base_settings.json file in app_settings folder and move any manually defined configurations there.`
120+
);
110121
appSettings = fs.readJson(appSettingsPath);
111122
}
112123
appSettings.contact_summary = await compilation.compileContactSummary(projectDir, options);
@@ -128,7 +139,9 @@ const compileAppSettingsForProject = async (projectDir, options) => {
128139

129140
function applyTransforms(app_settings, inherited) {
130141
function doDelete(target, rules) {
131-
if (!Array.isArray(rules)) throw new Error('.delete should be an array');
142+
if (!Array.isArray(rules)) {
143+
throw new Error('.delete should be an array');
144+
}
132145

133146
rules.forEach(k => {
134147
const parts = k.split('.');
@@ -142,7 +155,9 @@ function applyTransforms(app_settings, inherited) {
142155
}
143156

144157
function doReplace(target, rules) {
145-
if (typeof rules !== 'object') throw new Error('.replace should be an object');
158+
if (typeof rules !== 'object') {
159+
throw new Error('.replace should be an object');
160+
}
146161

147162
Object.keys(rules)
148163
.forEach(k => {
@@ -159,14 +174,22 @@ function applyTransforms(app_settings, inherited) {
159174
function doMerge(target, source) {
160175
Object.keys(target)
161176
.forEach(k => {
162-
if (Array.isArray(source[k])) target[k] = target[k].concat(source[k]);
163-
else if (typeof source[k] === 'object') doMerge(target[k], source[k]);
164-
else source[k] = target[k];
177+
if (Array.isArray(source[k])) {
178+
target[k] = target[k].concat(source[k]);
179+
}
180+
else if (typeof source[k] === 'object') {
181+
doMerge(target[k], source[k]);
182+
}
183+
else {
184+
source[k] = target[k];
185+
}
165186
});
166187
}
167188

168189
function doFilter(target, rules) {
169-
if (typeof rules !== 'object') throw new Error('.filter should be an object');
190+
if (typeof rules !== 'object') {
191+
throw new Error('.filter should be an object');
192+
}
170193

171194
Object.keys(rules)
172195
.forEach(k => {
@@ -177,11 +200,15 @@ function applyTransforms(app_settings, inherited) {
177200
parts.shift();
178201
}
179202

180-
if (!Array.isArray(rules[k])) throw new Error('.filter values must be arrays!');
203+
if (!Array.isArray(rules[k])) {
204+
throw new Error('.filter values must be arrays!');
205+
}
181206

182207
Object.keys(t[parts[0]])
183208
.forEach(tK => {
184-
if (!rules[k].includes(tK)) delete t[parts[0]][tK];
209+
if (!rules[k].includes(tK)) {
210+
delete t[parts[0]][tK];
211+
}
185212
});
186213
});
187214
}

src/fn/compress-pngs.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ module.exports = {
1212
promiseChain
1313
.then(() => info('Compressing PNG:', png, '…'))
1414
.then(() =>
15-
exec(['pngout-medic', `'${png}'`])
16-
.then(() => trace('Compressed', png))
17-
.catch(e => {
18-
if(e.status === 2) {
19-
info('Unable to compress further.');
20-
} else throw e;
21-
})),
22-
Promise.resolve())
15+
exec(['pngout-medic', `'${png}'`])
16+
.then(() => trace('Compressed', png))
17+
.catch(e => {
18+
if(e.status === 2) {
19+
info('Unable to compress further.');
20+
} else {
21+
throw e;
22+
}
23+
})),
24+
Promise.resolve())
2325
};

src/fn/compress-svgs.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ module.exports = {
1515
.then(() => svgo.optimize(fs.read(path), { path }))
1616
.then(result => fs.write(path, result.data))
1717
.then(() => trace('Compressed', path))
18-
.then(() => warn('Make sure you compare the content of your SVG files before merging to the default branch - sometimes optimising can change their contents!')),
19-
Promise.resolve())
18+
.then(() => warn(
19+
'Make sure you compare the content of your SVG files before merging to the default branch ' +
20+
'- sometimes optimising can change their contents!'
21+
)),
22+
Promise.resolve())
2023
};

0 commit comments

Comments
 (0)