-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add validations for dhis2 package.json files (#47)
* feat: add validations for dhis2 package.json files * fix: clean up code a bit * fix: only do husky checks on root packages * feat: add fine-grained style setup * feat: check for publish access and autofix if possible * chore: run pkg check * refactor: minimize the amount of json parsing * refactor: format json when writing * chore: trigger apply * feat: add validate command * fix: do not add publish config to root dir * refactor: remove package subcommand * fix: use specific options for validation * refactor: add space where needed * refactor: add groups directory * refactor: use the groups directory for config * refactor: add all to the groups * refactor: use singular for consistency * refactor: use force to overwrite configs
- Loading branch information
Showing
26 changed files
with
719 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
extends: ['@commitlint/config-conventional'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
version: 1 | ||
|
||
update_configs: | ||
- package_manager: "javascript" | ||
directory: "/" | ||
update_schedule: "live" | ||
default_assignees: | ||
- @dhis2/front-end | ||
version_requirement_updates: "increase_versions" | ||
- package_manager: "java:maven" | ||
directory: "/" | ||
update_schedule: "monthly" | ||
- package_manager: "docker" | ||
directory: "/" | ||
update_schedule: "weekly" | ||
- package_manager: "submodules" | ||
directory: "/" | ||
update_schedule: "weekly" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
version: 1 | ||
|
||
update_configs: | ||
- package_manager: "javascript" | ||
directory: "/" | ||
update_schedule: "live" | ||
default_assignees: | ||
- @dhis2/front-end | ||
version_requirement_updates: "increase_versions" | ||
- package_manager: "java:maven" | ||
directory: "/" | ||
update_schedule: "monthly" | ||
- package_manager: "docker" | ||
directory: "/" | ||
update_schedule: "weekly" | ||
- package_manager: "submodules" | ||
directory: "/" | ||
update_schedule: "weekly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_extends: .github |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const SEVERITY = 2 | ||
|
||
module.exports = { | ||
root: true, | ||
|
||
parser: 'babel-eslint', | ||
|
||
env: { | ||
browser: true, | ||
node: true, | ||
jest: true, | ||
}, | ||
|
||
parserOptions: { | ||
// latest standard is ok, eq. to 9 | ||
ecmaVersion: 2018, | ||
ecmaFeatures: { | ||
jsx: true, | ||
modules: true, | ||
}, | ||
}, | ||
|
||
rules: { | ||
'max-params': [ | ||
SEVERITY, | ||
{ | ||
max: 3, | ||
}, | ||
], | ||
'prefer-const': [ | ||
SEVERITY, | ||
{ | ||
destructuring: 'any', | ||
ignoreReadBeforeAssign: false, | ||
}, | ||
], | ||
'no-mixed-spaces-and-tabs': [SEVERITY], | ||
}, | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
const configure = require('../../config') | ||
const { configure, cleanup } = require('../../config') | ||
|
||
exports.command = 'install' | ||
exports.describe = | ||
'Install javascript tool configurations for use by IDE plugins' | ||
exports.handler = () => { | ||
configure(process.cwd()) | ||
const root = process.cwd() | ||
cleanup(root) | ||
configure(root, 'js', true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const log = require('@dhis2/cli-helpers-engine').reporter | ||
|
||
const { configure } = require('../config') | ||
|
||
exports.command = 'setup [group..]' | ||
|
||
exports.describe = 'Setup DHIS2 configurations for a/all group(s)' | ||
|
||
exports.builder = { | ||
force: { | ||
describe: 'Overwrites existing configuration', | ||
type: 'boolean', | ||
default: 'false', | ||
}, | ||
} | ||
|
||
exports.handler = argv => { | ||
log.info('Setting up configuration files...') | ||
const { force, group } = argv | ||
|
||
const root = process.cwd() | ||
|
||
configure(root, group, force) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
const fs = require('fs-extra') | ||
const path = require('path') | ||
|
||
const log = require('@dhis2/cli-helpers-engine').reporter | ||
|
||
const { selectFiles } = require('../files.js') | ||
const { stageFiles } = require('../git-files.js') | ||
const { groups, isValidGroup } = require('../groups.js') | ||
|
||
exports.command = 'validate [group..]' | ||
|
||
exports.describe = 'Validate DHIS2 configurations for a/all group(s)' | ||
|
||
exports.builder = { | ||
fix: { | ||
describe: 'Fix problems that can be fixed automatically', | ||
type: 'boolean', | ||
default: 'false', | ||
}, | ||
stage: { | ||
describe: | ||
'By default the changed files are staged automatically, use `--no-stage` to avoid staging files automatically.', | ||
type: 'boolean', | ||
default: 'true', | ||
}, | ||
all: { | ||
describe: | ||
'Default behaviour is to only format files staged with Git, use this option to format all files.', | ||
type: 'boolean', | ||
default: 'false', | ||
}, | ||
} | ||
|
||
exports.handler = argv => { | ||
const { fix, group, stage, all } = argv | ||
const root = process.cwd() | ||
|
||
const files = selectFiles(null, all, root) | ||
|
||
const reports = runners(files, group, fix) | ||
|
||
let violations = 0 | ||
const fixedFiles = [] | ||
|
||
for (const report of reports) { | ||
report.summarize() | ||
|
||
if (report.hasViolations) { | ||
violations += report.violations.length | ||
} | ||
|
||
if (fix) { | ||
const fixed = report.fix() | ||
fixedFiles.push(...fixed) | ||
} | ||
} | ||
|
||
if (violations > 0) { | ||
log.error(`${violations} file(s) violate the code standard.`) | ||
process.exit(1) | ||
} | ||
|
||
if (stage && fixedFiles.length > 0) { | ||
stageFiles(fixedFiles, root) | ||
} | ||
} | ||
|
||
function runners(files, group = ['all'], fix = false) { | ||
const validGroups = group.filter(isValidGroup) | ||
|
||
if (validGroups.length === 0) { | ||
log.warn( | ||
`No valid group selected, use one of: ${Object.keys(groups).join( | ||
', ' | ||
)}` | ||
) | ||
} else { | ||
log.info(`Running validations for group(s): ${validGroups.join(', ')}`) | ||
} | ||
|
||
return validGroups | ||
.map(g => groups[g].tools.map(fn => fn(files, fix))) | ||
.reduce((a, b) => a.concat(b), []) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.