Skip to content

Commit

Permalink
feat(eslint): add import order rule (#334)
Browse files Browse the repository at this point in the history
This requires imports to be sorted, and can automatically be fixed by eslint

Co-authored-by: ismay <ismay@ismaywolff.nl>
  • Loading branch information
varl and ismay authored Dec 16, 2020
1 parent 2aab0c3 commit c7b9991
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 27 deletions.
10 changes: 10 additions & 0 deletions config/js/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,15 @@ module.exports = {
],
'no-mixed-spaces-and-tabs': [SEVERITY],
'prettier/prettier': [SEVERITY],
'import/order': [
SEVERITY,
{
'newlines-between': 'never',
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
},
],
},
}
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { bundledConfigPaths } = require('./src/utils/groups.js')
const command = require('./src/index.js')
const { bundledConfigPaths } = require('./src/utils/groups.js')

exports.config = bundledConfigPaths()
exports.command = command
1 change: 0 additions & 1 deletion src/commands/commit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const log = require('@dhis2/cli-helpers-engine').reporter
const { namespace } = require('@dhis2/cli-helpers-engine')

const { commitlint } = require('../tools/commitlint.js')

const commitCmd = yargs => {
Expand Down
5 changes: 1 addition & 4 deletions src/commands/install.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
const { reporter, prompt } = require('@dhis2/cli-helpers-engine')

const { log } = reporter

const { configure } = require('../utils/config.js')
const { printGroups, projects } = require('../utils/groups.js')

Expand Down Expand Up @@ -36,7 +33,7 @@ exports.builder = {

exports.handler = async argv => {
if (argv.listGroups) {
log.print(printGroups())
reporter.print(printGroups())
process.exit(0)
}

Expand Down
1 change: 0 additions & 1 deletion src/commands/javascript.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { namespace } = require('@dhis2/cli-helpers-engine')
const log = require('@dhis2/cli-helpers-engine').reporter

const { eslint } = require('../tools/eslint.js')
const { selectFiles } = require('../utils/files.js')
const { sayFilesChecked, sayNoFiles } = require('../utils/std-log-messages.js')
Expand Down
1 change: 0 additions & 1 deletion src/commands/structured-text.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { namespace } = require('@dhis2/cli-helpers-engine')
const log = require('@dhis2/cli-helpers-engine').reporter

const { prettier } = require('../tools/prettier.js')
const { selectFiles } = require('../utils/files.js')
const { sayFilesChecked, sayNoFiles } = require('../utils/std-log-messages.js')
Expand Down
2 changes: 1 addition & 1 deletion src/tools/commitlint.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { bin } = require('../utils/run.js')
const { COMMITLINT_CONFIG } = require('../utils/paths.js')
const { bin } = require('../utils/run.js')

exports.commitlint = ({ config = COMMITLINT_CONFIG, file }) => {
const cmd = 'commitlint'
Expand Down
2 changes: 1 addition & 1 deletion src/tools/eslint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { bin } = require('../utils/run.js')
const { resolveIgnoreFile } = require('../utils/files.js')
const { PACKAGE_ROOT } = require('../utils/paths.js')
const { bin } = require('../utils/run.js')

exports.eslint = ({ files = [], apply = false, config }) => {
const ignoreFile = resolveIgnoreFile(['.eslintignore'])
Expand Down
3 changes: 1 addition & 2 deletions src/tools/prettier.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const log = require('@dhis2/cli-helpers-engine').reporter

const { bin } = require('../utils/run.js')
const { resolveIgnoreFile } = require('../utils/files.js')
const { bin } = require('../utils/run.js')

exports.prettier = ({ files = [], apply = false, config }) => {
const ignoreFile = resolveIgnoreFile(['.prettierignore'])
Expand Down
4 changes: 1 addition & 3 deletions src/utils/config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const path = require('path')

const fs = require('fs-extra')

const log = require('@dhis2/cli-helpers-engine').reporter
const fs = require('fs-extra')

function copy(from, to, overwrite = true) {
try {
Expand Down
8 changes: 3 additions & 5 deletions src/utils/files.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
const fg = require('fast-glob')
const fs = require('fs-extra')
const path = require('path')

const log = require('@dhis2/cli-helpers-engine').reporter

const { spawn } = require('./run.js')
const fg = require('fast-glob')
const fs = require('fs-extra')
const { CONSUMING_ROOT } = require('./paths.js')
const { spawn } = require('./run.js')

// blacklists for files
const blacklist = [
Expand Down
2 changes: 0 additions & 2 deletions src/utils/groups.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const path = require('path')

const {
BROWSERSLIST_CONFIG,
ESLINT_CONFIG,
Expand All @@ -10,7 +9,6 @@ const {
DEPENDABOT_CONFIG,
EDITORCONFIG_CONFIG,
SEMANTIC_PR_CONFIG,

LOCAL_ESLINT_REACT_CONFIG,
LOCAL_PRETTIER_CONFIG,
LOCAL_ESLINT_CONFIG,
Expand Down
3 changes: 1 addition & 2 deletions tests/configs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const test = require('tape')
const path = require('path')

const test = require('tape')
const { config } = require('../index.js')

test('prettier config resolves to non-empty object', t => {
Expand Down
2 changes: 0 additions & 2 deletions tests/group-resolution.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const test = require('tape')

const {
groups,
projects,
Expand All @@ -9,7 +8,6 @@ const {
expandGroupAll,
bundledConfigPaths,
} = require('../src/utils/groups.js')

const {
BROWSERSLIST_CONFIG,
HUSKY_CONFIG,
Expand Down
1 change: 0 additions & 1 deletion tests/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const test = require('tape')

const { command, config } = require('../index.js')

test('base exports are objects', t => {
Expand Down

0 comments on commit c7b9991

Please sign in to comment.