From be0a129429c16ab632cb43591914e0e8672d14bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Thu, 19 Mar 2020 09:59:12 +0000 Subject: [PATCH 1/7] move general rules out of app config --- lib/configs/app.js | 4 +--- lib/configs/browser.js | 1 + lib/configs/recommended.js | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/configs/app.js b/lib/configs/app.js index 92a4fc6d..20ac1486 100644 --- a/lib/configs/app.js +++ b/lib/configs/app.js @@ -3,9 +3,7 @@ module.exports = { rules: { 'github/authenticity-token': 'error', 'github/js-class-name': 'error', - 'github/no-d-none': 'error', - 'github/no-dataset': 'error', - 'github/no-then': 'error' + 'github/no-d-none': 'error' }, extends: [require.resolve('./recommended'), require.resolve('./browser')] } diff --git a/lib/configs/browser.js b/lib/configs/browser.js index aceab841..f236b75b 100644 --- a/lib/configs/browser.js +++ b/lib/configs/browser.js @@ -8,6 +8,7 @@ module.exports = { 'github/async-preventdefault': 'error', 'github/get-attribute': 'error', 'github/no-blur': 'error', + 'github/no-dataset': 'error', 'github/no-innerText': 'error', 'github/unescaped-html-literal': 'error' }, diff --git a/lib/configs/recommended.js b/lib/configs/recommended.js index 43bc3fbc..c164a398 100644 --- a/lib/configs/recommended.js +++ b/lib/configs/recommended.js @@ -21,6 +21,7 @@ module.exports = { 'func-style': ['error', 'declaration', {allowArrowFunctions: true}], 'github/array-foreach': 'error', 'github/no-implicit-buggy-globals': 'error', + 'github/no-then': 'error', 'import/default': 'error', 'import/export': 'error', 'import/first': 'error', From c0b6a739f949a916e43b3508f69398d2b96d1d54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Thu, 19 Mar 2020 10:03:31 +0000 Subject: [PATCH 2/7] remove es6 config docs --- docs/configs.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/configs.md b/docs/configs.md index 19ba9353..013ed855 100644 --- a/docs/configs.md +++ b/docs/configs.md @@ -22,9 +22,6 @@ $ node_modules/.bin/eslint-github-init A base layer of configuration recommended for any JS project. The [Prettier](https://prettier.io/) formatter is used to format code. -### `plugin:github/es6` - -Recommended rules when using Babel to transpile features from ES2015+. ### `plugin:github/app` From 6b2380285a8fc1b0cc80349d27ee5186b1fa66eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Thu, 19 Mar 2020 10:04:13 +0000 Subject: [PATCH 3/7] rename `app` config to `internal` config --- docs/configs.md | 5 ++--- lib/configs/{app.js => internal.js} | 0 lib/index.js | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) rename lib/configs/{app.js => internal.js} (100%) diff --git a/docs/configs.md b/docs/configs.md index 013ed855..e2667608 100644 --- a/docs/configs.md +++ b/docs/configs.md @@ -22,7 +22,6 @@ $ node_modules/.bin/eslint-github-init A base layer of configuration recommended for any JS project. The [Prettier](https://prettier.io/) formatter is used to format code. +### `plugin:github/internal` -### `plugin:github/app` - -Recommended rules when writing a browser application. +Recommended rules when writing a internal GitHub app. diff --git a/lib/configs/app.js b/lib/configs/internal.js similarity index 100% rename from lib/configs/app.js rename to lib/configs/internal.js diff --git a/lib/index.js b/lib/index.js index e0a4c486..db2f060a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -15,7 +15,7 @@ module.exports = { 'unescaped-html-literal': require('./rules/unescaped-html-literal') }, configs: { - app: require('./configs/app'), + internal: require('./configs/internal'), browser: require('./configs/browser'), recommended: require('./configs/recommended'), typescript: require('./configs/typescript') From 70abdb8c750a28a474d695b059c807e050b0dce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Thu, 19 Mar 2020 10:18:24 +0000 Subject: [PATCH 4/7] fix `github/no-then` violations --- bin/eslint-github-init.js | 4 +- bin/github-lint.js | 66 ++++++++++---------- bin/npm-check-github-package-requirements.js | 3 + 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/bin/eslint-github-init.js b/bin/eslint-github-init.js index 7300b273..624db86f 100755 --- a/bin/eslint-github-init.js +++ b/bin/eslint-github-init.js @@ -47,7 +47,7 @@ const questions = [ } ] -inquirer.prompt(questions).then(answers => { +for (const answers of inquirer.prompt(questions)) { const eslintrc = {extends: ['plugin:github/es6']} if (answers.project === 'app') { @@ -83,4 +83,4 @@ inquirer.prompt(questions).then(answers => { prettierConfig.push('') fs.writeFileSync(path.resolve(process.cwd(), 'prettier.config.js'), prettierConfig.join('\n'), 'utf8') -}) +} diff --git a/bin/github-lint.js b/bin/github-lint.js index 820cecd3..8c68f582 100755 --- a/bin/github-lint.js +++ b/bin/github-lint.js @@ -17,48 +17,50 @@ function execFile(command, args) { }) } -;(async function() { - let runs = 0 - const codes = [] - const commands = [] +try { + ;(async function() { + let runs = 0 + const codes = [] + const commands = [] - let eslintOptions = ['--report-unused-disable-directives', '.'] + let eslintOptions = ['--report-unused-disable-directives', '.'] - if (hasBasicColorSupport) { - eslintOptions = eslintOptions.concat(['--color']) - } + if (hasBasicColorSupport) { + eslintOptions = eslintOptions.concat(['--color']) + } - const isTypeScriptProject = fs.existsSync('tsconfig.json') + const isTypeScriptProject = fs.existsSync('tsconfig.json') - if (isTypeScriptProject) { - eslintOptions = eslintOptions.concat(['--ext', '.js,.ts,.tsx']) - } + if (isTypeScriptProject) { + eslintOptions = eslintOptions.concat(['--ext', '.js,.ts,.tsx']) + } - commands.push(['eslint', eslintOptions]) + commands.push(['eslint', eslintOptions]) - if (isTypeScriptProject) { - commands.push(['tsc', ['--noEmit']]) - } + if (isTypeScriptProject) { + commands.push(['tsc', ['--noEmit']]) + } - for (const [command, args] of commands) { - if (runs > 0) process.stderr.write('\n') - process.stderr.write(`> ${command} ${args.join(' ')}\n`) + for (const [command, args] of commands) { + if (runs > 0) process.stderr.write('\n') + process.stderr.write(`> ${command} ${args.join(' ')}\n`) - const {code, stdout, stderr} = await execFile(command, args) - codes.push(code) - if (stderr) process.stderr.write(stderr) - if (stdout) process.stdout.write(stdout) + const {code, stdout, stderr} = await execFile(command, args) + codes.push(code) + if (stderr) process.stderr.write(stderr) + if (stdout) process.stdout.write(stdout) - runs++ - } + runs++ + } - const nonzero = codes.find(code => code !== 0) - if (nonzero) { - process.stderr.write(`\nCommand failed: ${nonzero}\n`) - process.exit(nonzero) - } -})().catch(error => { + const nonzero = codes.find(code => code !== 0) + if (nonzero) { + process.stderr.write(`\nCommand failed: ${nonzero}\n`) + process.exit(nonzero) + } + }) +} catch (error) { setTimeout(() => { throw error }) -}) +} diff --git a/bin/npm-check-github-package-requirements.js b/bin/npm-check-github-package-requirements.js index 88c9aa41..236d266c 100755 --- a/bin/npm-check-github-package-requirements.js +++ b/bin/npm-check-github-package-requirements.js @@ -12,10 +12,13 @@ function run() { process.stdout.write(`1..${checks.length}\n`) for (const [count, name, callback] of checks) { Promise.resolve() + // eslint-disable-next-line github/no-then .then(callback) + // eslint-disable-next-line github/no-then .then(() => { process.stdout.write(`ok ${count} - ${name}\n`) }) + // eslint-disable-next-line github/no-then .catch(error => { process.stdout.write(`not ok ${count} - ${name}\n ${error}\n`) }) From 3fcb3b7fe70f452eb84f39a3d847d623050ce2a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Thu, 19 Mar 2020 13:33:37 +0000 Subject: [PATCH 5/7] actually do a `await` / `async` conversion --- bin/eslint-github-init.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/eslint-github-init.js b/bin/eslint-github-init.js index 624db86f..7a70377d 100755 --- a/bin/eslint-github-init.js +++ b/bin/eslint-github-init.js @@ -47,7 +47,8 @@ const questions = [ } ] -for (const answers of inquirer.prompt(questions)) { +;(async function() { + const answers = await inquirer.prompt(questions) const eslintrc = {extends: ['plugin:github/es6']} if (answers.project === 'app') { @@ -83,4 +84,4 @@ for (const answers of inquirer.prompt(questions)) { prettierConfig.push('') fs.writeFileSync(path.resolve(process.cwd(), 'prettier.config.js'), prettierConfig.join('\n'), 'utf8') -} +})() From 4f0b7bd71585fb63afe2e9f23bd28deebfc1ad09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Thu, 19 Mar 2020 13:33:59 +0000 Subject: [PATCH 6/7] make sure to call top-level async function --- bin/github-lint.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/github-lint.js b/bin/github-lint.js index 8c68f582..916d4f68 100755 --- a/bin/github-lint.js +++ b/bin/github-lint.js @@ -58,7 +58,7 @@ try { process.stderr.write(`\nCommand failed: ${nonzero}\n`) process.exit(nonzero) } - }) + })() } catch (error) { setTimeout(() => { throw error From a9f54ea488ba6afbaedb6c04b1fd1c802a07c640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Thu, 19 Mar 2020 13:58:21 +0000 Subject: [PATCH 7/7] move try catch into async function --- bin/github-lint.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bin/github-lint.js b/bin/github-lint.js index 916d4f68..76f8df21 100755 --- a/bin/github-lint.js +++ b/bin/github-lint.js @@ -17,8 +17,8 @@ function execFile(command, args) { }) } -try { - ;(async function() { +;(async function() { + try { let runs = 0 const codes = [] const commands = [] @@ -58,9 +58,9 @@ try { process.stderr.write(`\nCommand failed: ${nonzero}\n`) process.exit(nonzero) } - })() -} catch (error) { - setTimeout(() => { - throw error - }) -} + } catch (error) { + setTimeout(() => { + throw error + }) + } +})()