Skip to content

Commit

Permalink
style: simplify eslint and prettier config
Browse files Browse the repository at this point in the history
  • Loading branch information
iiroj committed Apr 26, 2020
1 parent b746290 commit eed6198
Show file tree
Hide file tree
Showing 39 changed files with 165 additions and 627 deletions.
18 changes: 15 additions & 3 deletions .eslintrc.json
@@ -1,11 +1,23 @@
{
"extends": ["okonet/node"],
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 6,
"ecmaFeatures": {
"experimentalObjectRestSpread": true
},
"sourceType": "script"
},
"env": {
"es6": true,
"node": true
},
"extends": ["eslint:recommended", "prettier"],
"plugins": ["node", "import", "prettier"],
"rules": {
"no-console": "off",
"node/no-unsupported-features/node-builtins": "off",
"node/no-unsupported-features/es-syntax": ["error", { "version": ">=10.13.0" }],
"node/no-unsupported-features/es-builtins": ["error", { "version": ">=10.13.0" }],
"prettier/prettier": "off",
"require-atomic-updates": "off"
"prettier/prettier": "error"
}
}
4 changes: 2 additions & 2 deletions .lintstagedrc.json
@@ -1,4 +1,4 @@
{
"*.{js,json,md}": "prettier --write",
"*.js": "npm run lint:base -- --fix"
"*.js": "eslint --fix",
"*.{json,md}": "prettier --write"
}
8 changes: 0 additions & 8 deletions .prettierrc.js

This file was deleted.

5 changes: 5 additions & 0 deletions .prettierrc.json
@@ -0,0 +1,5 @@
{
"printWidth": 100,
"singleQuote": true,
"semi": false
}
6 changes: 3 additions & 3 deletions bin/lint-staged.js
Expand Up @@ -15,8 +15,8 @@ const pkg = require('../package.json')
require('please-upgrade-node')(
Object.assign({}, pkg, {
engines: {
node: '>=10.13.0' // First LTS release of 'Dubnium'
}
node: '>=10.13.0', // First LTS release of 'Dubnium'
},
})
)

Expand Down Expand Up @@ -81,7 +81,7 @@ const options = {
quiet: !!cmdline.quiet,
relative: !!cmdline.relative,
shell: !!cmdline.shell,
verbose: !!cmdline.verbose
verbose: !!cmdline.verbose,
}

debug('Options parsed from command-line:', options)
Expand Down
2 changes: 1 addition & 1 deletion lib/execGit.js
Expand Up @@ -9,7 +9,7 @@ module.exports = async function execGit(cmd, options = {}) {
const { stdout } = await execa('git', [].concat(cmd), {
...options,
all: true,
cwd: options.cwd || process.cwd()
cwd: options.cwd || process.cwd(),
})
return stdout
} catch ({ all }) {
Expand Down
2 changes: 1 addition & 1 deletion lib/file.js
Expand Up @@ -59,5 +59,5 @@ const writeFile = async (filename, buffer) => {
module.exports = {
readFile,
unlink,
writeFile
writeFile,
}
4 changes: 2 additions & 2 deletions lib/generateTasks.js
Expand Up @@ -21,7 +21,7 @@ module.exports = function generateTasks({
cwd = process.cwd(),
gitDir,
files,
relative = false
relative = false,
}) {
debug('Generating linter tasks')

Expand All @@ -46,7 +46,7 @@ module.exports = function generateTasks({
// If pattern doesn't look like a path, enable `matchBase` to
// match against filenames in every directory. This makes `*.js`
// match both `test.js` and `subdirectory/test.js`.
matchBase: !pattern.includes('/')
matchBase: !pattern.includes('/'),
}
).map((file) => normalize(relative ? file : path.resolve(cwd, file)))

Expand Down
10 changes: 5 additions & 5 deletions lib/gitWorkflow.js
Expand Up @@ -13,7 +13,7 @@ const {
GetBackupStashError,
HideUnstagedChangesError,
RestoreMergeStatusError,
RestoreUnstagedChangesError
RestoreUnstagedChangesError,
} = require('./symbols')

const MERGE_HEAD = 'MERGE_HEAD'
Expand Down Expand Up @@ -52,7 +52,7 @@ const GIT_DIFF_ARGS = [
'--no-ext-diff', // disable external diff tools for consistent behaviour
'--src-prefix=a/', // force prefix for consistent behaviour
'--dst-prefix=b/', // force prefix for consistent behaviour
'--patch' // output a patch that can be applied
'--patch', // output a patch that can be applied
]
const GIT_APPLY_ARGS = ['-v', '--whitespace=nowarn', '--recount', '--unidiff-zero']

Expand Down Expand Up @@ -125,7 +125,7 @@ class GitWorkflow {
await Promise.all([
readFile(this.mergeHeadFilename).then((buffer) => (this.mergeHeadBuffer = buffer)),
readFile(this.mergeModeFilename).then((buffer) => (this.mergeModeBuffer = buffer)),
readFile(this.mergeMsgFilename).then((buffer) => (this.mergeMsgBuffer = buffer))
readFile(this.mergeMsgFilename).then((buffer) => (this.mergeMsgBuffer = buffer)),
])
debug('Done backing up merge state!')
}
Expand All @@ -139,7 +139,7 @@ class GitWorkflow {
await Promise.all([
this.mergeHeadBuffer && writeFile(this.mergeHeadFilename, this.mergeHeadBuffer),
this.mergeModeBuffer && writeFile(this.mergeModeFilename, this.mergeModeBuffer),
this.mergeMsgBuffer && writeFile(this.mergeMsgFilename, this.mergeMsgBuffer)
this.mergeMsgBuffer && writeFile(this.mergeMsgFilename, this.mergeMsgBuffer),
])
debug('Done restoring merge state!')
} catch (error) {
Expand Down Expand Up @@ -252,7 +252,7 @@ class GitWorkflow {
const matchedFileChunks = chunkFiles({
baseDir: this.gitDir,
files,
maxArgLength: this.maxArgLength
maxArgLength: this.maxArgLength,
})

// These additions per chunk are run "serially" to prevent race conditions.
Expand Down
8 changes: 4 additions & 4 deletions lib/index.js
Expand Up @@ -30,8 +30,8 @@ function loadConfig(configPath) {
'.lintstagedrc.yaml',
'.lintstagedrc.yml',
'.lintstagedrc.js',
'lint-staged.config.js'
]
'lint-staged.config.js',
],
})

return configPath ? explorer.load(resolveConfig(configPath)) : explorer.search()
Expand Down Expand Up @@ -73,7 +73,7 @@ module.exports = async function lintStaged(
relative = false,
shell = false,
stash = true,
verbose = false
verbose = false,
} = {},
logger = console
) {
Expand Down Expand Up @@ -116,7 +116,7 @@ module.exports = async function lintStaged(
relative,
shell,
stash,
verbose
verbose,
},
logger
)
Expand Down
2 changes: 1 addition & 1 deletion lib/makeCmdTasks.js
Expand Up @@ -50,7 +50,7 @@ module.exports = async function makeCmdTasks({ commands, files, gitDir, shell, v
cmdTasks.push({
title,
command,
task: resolveTaskFn({ command, files, gitDir, isFn, shell, verbose })
task: resolveTaskFn({ command, files, gitDir, isFn, shell, verbose }),
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/messages.js
Expand Up @@ -50,5 +50,5 @@ module.exports = {
SKIPPED_GIT_ERROR,
GIT_ERROR,
PREVENTED_EMPTY_COMMIT,
RESTORE_STASH_EXAMPLE
RESTORE_STASH_EXAMPLE,
}
2 changes: 1 addition & 1 deletion lib/resolveTaskFn.js
Expand Up @@ -80,7 +80,7 @@ module.exports = function resolveTaskFn({
isFn,
relative,
shell = false,
verbose = false
verbose = false,
}) {
const [cmd, ...args] = parseArgsStringToArgv(command)
debug('cmd:', cmd)
Expand Down
30 changes: 15 additions & 15 deletions lib/runAll.js
Expand Up @@ -19,7 +19,7 @@ const {
NO_STAGED_FILES,
NO_TASKS,
SKIPPED_GIT_ERROR,
skippingBackup
skippingBackup,
} = require('./messages')
const resolveGitRepo = require('./resolveGitRepo')
const {
Expand All @@ -30,7 +30,7 @@ const {
hasPartiallyStagedFiles,
restoreOriginalStateEnabled,
restoreOriginalStateSkipped,
restoreUnstagedChangesSkipped
restoreUnstagedChangesSkipped,
} = require('./state')
const { GitRepoError, GetStagedFilesError, GitError } = require('./symbols')

Expand Down Expand Up @@ -66,7 +66,7 @@ const runAll = async (
relative = false,
shell = false,
stash = true,
verbose = false
verbose = false,
},
logger = console
) => {
Expand Down Expand Up @@ -119,7 +119,7 @@ const runAll = async (
ctx,
dateFormat: false,
exitOnError: false,
renderer: getRenderer({ debug, quiet })
renderer: getRenderer({ debug, quiet }),
}

const listrTasks = []
Expand All @@ -137,7 +137,7 @@ const runAll = async (
files: task.fileList,
gitDir,
shell,
verbose
verbose,
})

// Add files from task to match set
Expand All @@ -155,15 +155,15 @@ const runAll = async (
// and we want to abort on errors
...listrOptions,
concurrent: false,
exitOnError: true
exitOnError: true,
}),
skip: () => {
// Skip task when no files matched
if (task.fileList.length === 0) {
return `No staged files match ${task.pattern}`
}
return false
}
},
})
}

Expand All @@ -178,7 +178,7 @@ const runAll = async (
// Skip chunk when no every task is skipped (due to no matches)
if (chunkListrTasks.every((task) => task.skip())) return 'No tasks to run.'
return false
}
},
})
}

Expand All @@ -199,37 +199,37 @@ const runAll = async (
[
{
title: 'Preparing...',
task: (ctx) => git.prepare(ctx)
task: (ctx) => git.prepare(ctx),
},
{
title: 'Hiding unstaged changes to partially staged files...',
task: (ctx) => git.hideUnstagedChanges(ctx),
enabled: hasPartiallyStagedFiles
enabled: hasPartiallyStagedFiles,
},
...listrTasks,
{
title: 'Applying modifications...',
task: (ctx) => git.applyModifications(ctx),
skip: applyModificationsSkipped
skip: applyModificationsSkipped,
},
{
title: 'Restoring unstaged changes to partially staged files...',
task: (ctx) => git.restoreUnstagedChanges(ctx),
enabled: hasPartiallyStagedFiles,
skip: restoreUnstagedChangesSkipped
skip: restoreUnstagedChangesSkipped,
},
{
title: 'Reverting to original state because of errors...',
task: (ctx) => git.restoreOriginalState(ctx),
enabled: restoreOriginalStateEnabled,
skip: restoreOriginalStateSkipped
skip: restoreOriginalStateSkipped,
},
{
title: 'Cleaning up...',
task: (ctx) => git.cleanup(ctx),
enabled: cleanupEnabled,
skip: cleanupSkipped
}
skip: cleanupSkipped,
},
],
listrOptions
)
Expand Down
6 changes: 3 additions & 3 deletions lib/state.js
Expand Up @@ -6,14 +6,14 @@ const {
TaskError,
RestoreOriginalStateError,
GitError,
RestoreUnstagedChangesError
RestoreUnstagedChangesError,
} = require('./symbols')

const getInitialState = () => ({
hasPartiallyStagedFiles: null,
shouldBackup: null,
errors: new Set([]),
output: []
output: [],
})

const hasPartiallyStagedFiles = (ctx) => ctx.hasPartiallyStagedFiles
Expand Down Expand Up @@ -84,5 +84,5 @@ module.exports = {
restoreOriginalStateEnabled,
restoreOriginalStateSkipped,
cleanupEnabled,
cleanupSkipped
cleanupSkipped,
}
2 changes: 1 addition & 1 deletion lib/symbols.js
Expand Up @@ -21,5 +21,5 @@ module.exports = {
RestoreMergeStatusError,
RestoreOriginalStateError,
RestoreUnstagedChangesError,
TaskError
TaskError,
}
2 changes: 1 addition & 1 deletion lib/validateConfig.js
Expand Up @@ -15,7 +15,7 @@ const TEST_DEPRECATED_KEYS = new Map([
['ignore', (key) => Array.isArray(key)],
['subTaskConcurrency', (key) => typeof key === 'number'],
['renderer', (key) => typeof key === 'string'],
['relative', (key) => typeof key === 'boolean']
['relative', (key) => typeof key === 'boolean'],
])

const formatError = (helpMsg) => `● Validation Error:
Expand Down
10 changes: 2 additions & 8 deletions package.json
Expand Up @@ -21,9 +21,7 @@
],
"scripts": {
"cz": "git-cz",
"lint:base": "eslint --rule \"prettier/prettier: 2\"",
"lint": "npm run lint:base -- .",
"lint:fix": "npm run lint -- --fix",
"lint": "eslint .",
"pretest": "npm run lint",
"test": "jest --coverage",
"test:watch": "jest --watch"
Expand Down Expand Up @@ -52,18 +50,14 @@
"@babel/core": "^7.9.0",
"@babel/plugin-proposal-object-rest-spread": "^7.9.5",
"@babel/preset-env": "^7.9.5",
"babel-eslint": "^10.1.0",
"babel-eslint": "10.1.0",
"babel-jest": "^25.3.0",
"consolemock": "^1.1.0",
"eslint": "^6.8.0",
"eslint-config-okonet": "^7.0.2",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-flowtype": "^4.7.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-react": "^7.19.0",
"fs-extra": "^9.0.0",
"husky": "^4.2.5",
"jest": "^25.3.0",
Expand Down
2 changes: 1 addition & 1 deletion test/__mocks__/advanced-config.js
@@ -1,4 +1,4 @@
module.exports = {
'*.css': (filenames) => `echo ${filenames.join(' ')}`,
'*.js': (filenames) => filenames.map((filename) => `echo ${filename}`)
'*.js': (filenames) => filenames.map((filename) => `echo ${filename}`),
}

0 comments on commit eed6198

Please sign in to comment.