Skip to content

Commit

Permalink
Merge pull request #852 from okonet/listr2
Browse files Browse the repository at this point in the history
feat: replace listr with listr2
  • Loading branch information
iiroj committed Apr 28, 2020
2 parents c9adca5 + aba3421 commit 885a644
Show file tree
Hide file tree
Showing 50 changed files with 1,271 additions and 1,614 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
@@ -1,6 +1,6 @@
environment:
matrix:
- nodejs_version: '13'
- nodejs_version: '14'
- nodejs_version: '12'
- nodejs_version: '10'

Expand Down
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"
}
}
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Expand Up @@ -20,11 +20,11 @@ jobs:
test:
strategy:
matrix:
# Test with Node.js v10 (LTS), v12 (LTS), and v13 (latest)
# Test with Node.js v10 (LTS), v12 (LTS), and v14 (latest)
node:
- 10
- 12
- 13
- 14
# Test with Ubuntu and macOS
os:
- ubuntu-latest
Expand Down Expand Up @@ -58,9 +58,9 @@ jobs:
- run: yarn
# Run tests
- run: yarn test
# Upload coverage artifact from a single matrix entry
# Upload coverage artifact from Node.js LTS
- uses: actions/upload-artifact@v1
if: matrix.os == 'ubuntu-latest' && matrix.node == '13'
if: matrix.os == 'ubuntu-latest' && matrix.node == '12'
with:
name: coverage
path: coverage
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '13'
node-version: '12' # release using Node.js LTS
# Release using semantic-release.
# While this runs on all branches, it will only release latest from master
- uses: codfish/semantic-release-action@v1
Expand Down
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
}
46 changes: 29 additions & 17 deletions README.md
Expand Up @@ -72,7 +72,9 @@ Options:
-r, --relative pass relative filepaths to tasks (default: false)
-x, --shell skip parsing of tasks for better shell support (default:
false)
-h, --help output usage information
-v, --verbose show task output even when tasks succeed; by default only
failed output is shown (default: false)
-h, --help display help for command
```
- **`--allow-empty`**: By default, when linter tasks undo all staged changes, lint-staged will exit with an error and abort the commit. Use this flag to allow creating empty git commits.
Expand All @@ -88,6 +90,7 @@ Options:
- **`--quiet`**: Supress all CLI output, except from tasks.
- **`--relative`**: Pass filepaths relative to `process.cwd()` (where `lint-staged` runs) to tasks. Default is `false`.
- **`--shell`**: By default linter commands will be parsed for speed and security. This has the side-effect that regular shell scripts might not work as expected. You can skip parsing of commands with this option.
- **`--verbose`**: Show task output even when tasks succeed. By default only failed output is shown.
## Configuration
Expand Down Expand Up @@ -199,7 +202,7 @@ type TaskFn = (filenames: string[]) => string | string[] | Promise<string | stri
```js
// .lintstagedrc.js
module.exports = {
'**/*.js?(x)': filenames => filenames.map(filename => `prettier --write '${filename}'`)
'**/*.js?(x)': (filenames) => filenames.map((filename) => `prettier --write '${filename}'`)
}
```
Expand All @@ -217,7 +220,8 @@ module.exports = {
```js
// .lintstagedrc.js
module.exports = {
'**/*.js?(x)': filenames => (filenames.length > 10 ? 'eslint .' : `eslint ${filenames.join(' ')}`)
'**/*.js?(x)': (filenames) =>
filenames.length > 10 ? 'eslint .' : `eslint ${filenames.join(' ')}`
}
```
Expand All @@ -228,7 +232,7 @@ module.exports = {
const micromatch = require('micromatch')
module.exports = {
'*': allFiles => {
'*': (allFiles) => {
const match = micromatch(allFiles, ['*.js', '*.ts'])
return `eslint ${match.join(' ')}`
}
Expand All @@ -244,7 +248,7 @@ If for some reason you want to ignore files from the glob match, you can use `mi
const micromatch = require('micromatch')
module.exports = {
'*.js': files => {
'*.js': (files) => {
// from `files` filter those _NOT_ matching `*test.js`
const match = micromatch.not(files, '*test.js')
return `eslint ${match.join(' ')}`
Expand All @@ -260,9 +264,9 @@ Please note that for most cases, globs can achieve the same effect. For the abov
const path = require('path')
module.exports = {
'*.ts': absolutePaths => {
'*.ts': (absolutePaths) => {
const cwd = process.cwd()
const relativePaths = absolutePaths.map(file => path.relative(cwd, file))
const relativePaths = absolutePaths.map((file) => path.relative(cwd, file))
return `ng lint myProjectName --files ${relativePaths.join(' ')}`
}
}
Expand Down Expand Up @@ -422,27 +426,35 @@ Parameters to `lintStaged` are equivalent to their CLI counterparts:
```js
const success = await lintStaged({
allowEmpty: false,
concurrent: true,
configPath: './path/to/configuration/file',
cwd: process.cwd(),
debug: false,
maxArgLength: null,
relative: false,
shell: false,
quiet: false,
debug: false
relative: false,
shell: false
stash: true,
verbose: false
})
```
You can also pass config directly with `config` option:
```js
const success = await lintStaged({
config: {
'*.js': 'eslint --fix'
},
allowEmpty: false,
concurrent: true,
config: { '*.js': 'eslint --fix' },
cwd: process.cwd(),
debug: false,
maxArgLength: null,
quiet: false,
relative: false,
shell: false,
quiet: false,
debug: false
stash: true,
verbose: false
})
```
Expand Down Expand Up @@ -518,7 +530,7 @@ const { CLIEngine } = require('eslint')
const cli = new CLIEngine({})
module.exports = {
'*.js': files =>
'eslint --max-warnings=0 ' + files.filter(file => !cli.isPathIgnored(file)).join(' ')
'*.js': (files) =>
'eslint --max-warnings=0 ' + files.filter((file) => !cli.isPathIgnored(file)).join(' ')
}
```
12 changes: 9 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 All @@ -40,6 +40,11 @@ cmdline
.option('-q, --quiet', 'disable lint-staged’s own console output', false)
.option('-r, --relative', 'pass relative filepaths to tasks', false)
.option('-x, --shell', 'skip parsing of tasks for better shell support', false)
.option(
'-v, --verbose',
'show task output even when tasks succeed; by default only failed output is shown',
false
)
.parse(process.argv)

if (cmdline.debug) {
Expand Down Expand Up @@ -75,7 +80,8 @@ const options = {
stash: !!cmdline.stash, // commander inverts `no-<x>` flags to `!x`
quiet: !!cmdline.quiet,
relative: !!cmdline.relative,
shell: !!cmdline.shell
shell: !!cmdline.shell,
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
12 changes: 12 additions & 0 deletions lib/getRenderer.js
@@ -0,0 +1,12 @@
'use strict'

const getRenderer = ({ debug, quiet }, env = process.env) => {
if (quiet) return 'silent'
// Better support for dumb terminals: https://en.wikipedia.org/wiki/Computer_terminal#Dumb_terminals
const isDumbTerminal = env.TERM === 'dumb'
if (isDumbTerminal || env.NODE_ENV === 'test') return 'test'
if (debug) return 'verbose'
return 'update'
}

module.exports = getRenderer

0 comments on commit 885a644

Please sign in to comment.