diff --git a/README.md b/README.md index 6b602ec2..8d89cea5 100644 --- a/README.md +++ b/README.md @@ -24,4 +24,4 @@ Set up `npm run lint` script. } ``` -The `github-lint` command will run `eslint`, `flow` and flow coverage checking depending on your project configuration. +The `github-lint` command will run various checkers and linters depending on your project configuration. diff --git a/bin/eslint-github-init.js b/bin/eslint-github-init.js index efd67a4a..cd7f9d71 100755 --- a/bin/eslint-github-init.js +++ b/bin/eslint-github-init.js @@ -18,9 +18,6 @@ if (fs.existsSync(packagePath)) { const dependencies = Object.keys(packageJSON.dependencies || {}) const devDependencies = Object.keys(packageJSON.devDependencies || {}) - if (dependencies.includes('flow-bin') || devDependencies.includes('flow-bin')) { - defaults.typeSystem = 'flow' - } if (dependencies.includes('typescript') || devDependencies.includes('typescript')) { defaults.typeSystem = 'typescript' } @@ -45,7 +42,7 @@ const questions = [ type: 'list', name: 'typeSystem', message: 'What type system are you using?', - choices: ['flow', 'typescript', 'none'], + choices: ['typescript', 'none'], default: defaults.typeSystem } ] @@ -61,7 +58,6 @@ inquirer.prompt(questions).then(answers => { eslintrc.extends.push('plugin:github/browser') } - if (answers.typeSystem === 'flow') eslintrc.extends.push('plugin:github/flow') if (answers.typeSystem === 'typescript') { eslintrc.extends.push('plugin:github/typescript') eslintrc.parser = '@typescript-eslint/parser' @@ -85,8 +81,6 @@ inquirer.prompt(questions).then(answers => { fs.writeFileSync(path.resolve(process.cwd(), '.eslintrc.json'), JSON.stringify(eslintrc, null, ' '), 'utf8') const prettierConfig = [] - if (answers.typeSystem === 'flow') prettierConfig.push('/* @flow */') - prettierConfig.push("module.exports = require('eslint-plugin-github/prettier.config')") prettierConfig.push('') diff --git a/bin/flow-coverage.js b/bin/flow-coverage.js deleted file mode 100755 index 65c92bc7..00000000 --- a/bin/flow-coverage.js +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env node -// usage: flow-coverage -// -// Run flow coverage on project. - -const childProcess = require('child_process') -const flow = require('flow-bin') -const fs = require('fs') -const {join} = require('path') - -const execFile = (file, args) => - new Promise((resolve, reject) => { - childProcess.execFile( - file, - args, - { - maxBuffer: Infinity - }, - (error, stdout, stderr) => { - if (error) { - reject(error) - } else { - resolve({stdout, stderr}) - } - } - ) - }) - -async function execFileJSON(file, args) { - args.push('--json') - const {stdout, stderr} = await execFile(file, args) - if (stderr) { - return JSON.parse(stderr) - } else { - return JSON.parse(stdout) - } -} - -function computeCoverage(covered, uncovered) { - const total = covered + uncovered - if (total) { - return 100 * (covered / total) - } else { - return 100 - } -} - -async function getCoverage(path) { - const json = await execFileJSON(flow, ['coverage', path]) - if (json && json.expressions) { - const uncoveredCount = json.expressions['uncovered_count'] - const coveredCount = json.expressions['covered_count'] - const covered = computeCoverage(coveredCount, uncoveredCount) - return {path, uncoveredCount, coveredCount, covered} - } else { - return {path, uncoveredCount: 0, coveredCount: 0, covered: 0} - } -} - -async function startFlow() { - try { - await execFile(flow, ['start', '--wait']) - } catch (error) { - if (error.code === 11) { - /* already running */ - } else { - throw error - } - } -} - -// const ignore = [/\.flowconfig$/, /\.json$/, /\.test\.js$/, /\/__generated__\//, /\/flow-typed\//, /\/node_modules\//] -// -// async function flowList() { -// execFile('git', ['grep', '--name-only', '--', '@flow']) -// -// const paths = await execFileJSON(flow, ['ls']) -// return paths.filter(path => !ignore.some(re => re.test(path))) -// } - -async function grepFlowFiles() { - const {stdout} = await execFile('git', ['grep', '--null', '--name-only', '--', '@flow']) - return stdout.split('\0').filter(path => path) -} - -;(async function() { - let threshold = 0 - - const packageJsonPath = join(process.cwd(), 'package.json') - if (fs.existsSync(packageJsonPath)) { - const packageJson = require(packageJsonPath) - threshold = (packageJson.flow && packageJson.flow.coverageThreshold) || 0 - } - - await startFlow() - - const files = await grepFlowFiles() - - let totalCoveredCount = 0 - let totalUncoveredCount = 0 - - for (const file of files) { - const {path, covered, coveredCount, uncoveredCount} = await getCoverage(file) - process.stdout.write(`${covered.toFixed()}\t${path}\n`) - totalCoveredCount += coveredCount - totalUncoveredCount += uncoveredCount - } - - const totalCoverage = computeCoverage(totalCoveredCount, totalUncoveredCount) - - process.stdout.write(`${totalCoverage.toFixed()}\t(total)\n`) - if (totalCoverage < threshold) { - process.stderr.write(`expected at least ${threshold}% coverage, but was ${totalCoverage.toFixed()}%\n`) - process.exit(1) - } -})().catch(error => { - process.stderr.write(`${error}\n`) - process.exit(2) -}) diff --git a/bin/github-lint.js b/bin/github-lint.js index e9998be4..8adc278a 100755 --- a/bin/github-lint.js +++ b/bin/github-lint.js @@ -43,14 +43,6 @@ function execFile(command, args) { commands.push(['tsc', ['--noEmit']]) } - if (fs.existsSync('.flowconfig')) { - commands.push(['flow', ['check']]) - } - - if (packageJson && packageJson.flow && packageJson.flow.coverageThreshold) { - commands.push(['flow-coverage', []]) - } - for (const [command, args] of commands) { if (runs > 0) process.stderr.write('\n') process.stderr.write(`> ${command} ${args.join(' ')}\n`) diff --git a/docs/configs.md b/docs/configs.md index 7e6818f3..036a7c7c 100644 --- a/docs/configs.md +++ b/docs/configs.md @@ -26,10 +26,6 @@ A base layer of configuration recommended for any JS project. The [Prettier](htt Recommended rules when using Babel to transpile features from ES2015+. -### `plugin:github/flow` - -Recommended rules for projects using the [Flow type checker](https://flow.org/). - ### `plugin:github/app` Recommended rules when writing a browser application. diff --git a/docs/package-requirements.md b/docs/package-requirements.md index 647bfaae..6f55577b 100644 --- a/docs/package-requirements.md +++ b/docs/package-requirements.md @@ -20,4 +20,3 @@ Additional criteria for packages that are used at runtime rather than at build t * MUST not declare specific polyfills in `package.json` `"dependencies"`. However, they MAY implicitly depend on polyfills already present in the environment. * MUST not set or leak any global variables or monkey patch other object prototypes (with the exception of polyfills). * Polyfill libraries MUST have an associated [Working Draft](https://www.w3.org/2004/02/Process-20040205/tr.html#first-wd) specification published by a standards body. Polyfills based on Editor's Draft are too early to implement and depend on. -* SHOULD provide [Flow](https://flowtype.org) type definitions. diff --git a/docs/rules/no-flow-weak.md b/docs/rules/no-flow-weak.md deleted file mode 100644 index 2b4c1c5e..00000000 --- a/docs/rules/no-flow-weak.md +++ /dev/null @@ -1,3 +0,0 @@ -# No `@flow weak` - -Do not enable Flow type checker _weak mode_ by using a `/* @flow weak */` comment. Instead explicitly Flow in _strict mode_ with a comment at the top of the file, `/* @flow */`. diff --git a/docs/rules/no-noflow.md b/docs/rules/no-noflow.md deleted file mode 100644 index 7a25e663..00000000 --- a/docs/rules/no-noflow.md +++ /dev/null @@ -1,3 +0,0 @@ -# No `@noflow` - -Do not disable the Flow type checker by using a `/* @noflow */` comment. Instead explicitly Flow at the top of the file with `/* @flow */`. diff --git a/lib/configs/flow.js b/lib/configs/flow.js deleted file mode 100644 index 84050a45..00000000 --- a/lib/configs/flow.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = { - parser: 'babel-eslint', - plugins: ['flowtype', 'github'], - rules: { - 'flowtype/define-flow-type': 'error', - 'flowtype/require-valid-file-annotation': ['error', 'always', {annotationStyle: 'block'}], - 'flowtype/use-flow-type': 'error', - 'flowtype/no-flow-fix-me-comments': 'error', - 'flowtype/no-primitive-constructor-types': 'error', - 'flowtype/no-weak-types': 'error', - 'github/no-flow-weak': 'error', - 'github/no-noflow': 'error' - } -} diff --git a/lib/index.js b/lib/index.js index 43db24d6..77994b62 100644 --- a/lib/index.js +++ b/lib/index.js @@ -5,16 +5,13 @@ module.exports = { 'async-preventdefault': require('./rules/async-preventdefault'), 'authenticity-token': require('./rules/authenticity-token'), 'dependency-graph': require('./rules/dependency-graph'), - 'flow-to-typescript': require('./rules/flow-to-typescript'), 'get-attribute': require('./rules/get-attribute'), 'js-class-name': require('./rules/js-class-name'), 'no-blur': require('./rules/no-blur'), 'no-d-none': require('./rules/no-d-none'), 'no-dataset': require('./rules/no-dataset'), - 'no-flow-weak': require('./rules/no-flow-weak'), 'no-implicit-buggy-globals': require('./rules/no-implicit-buggy-globals'), 'no-innerText': require('./rules/no-innerText'), - 'no-noflow': require('./rules/no-noflow'), 'no-then': require('./rules/no-then'), 'unescaped-html-literal': require('./rules/unescaped-html-literal'), 'unused-export': require('./rules/unused-export'), @@ -24,7 +21,6 @@ module.exports = { app: require('./configs/app'), browser: require('./configs/browser'), es6: require('./configs/es6'), - flow: require('./configs/flow'), node: require('./configs/node'), recommended: require('./configs/recommended'), typescript: require('./configs/typescript') diff --git a/lib/rules/flow-to-typescript.js b/lib/rules/flow-to-typescript.js deleted file mode 100644 index b681d93e..00000000 --- a/lib/rules/flow-to-typescript.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - meta: { - docs: {}, - schema: [] - }, - - create(context) { - return { - Program(node) { - const comments = context.getSourceCode().getAllComments() - const enabledTypeChecker = comments.some(comment => comment.value.trim().match(/@ts-check|@flow/)) - if (!enabledTypeChecker) { - context.report(node, 'File must be type checked by TypeScript or Flow.') - } - } - } - } -} diff --git a/lib/rules/no-flow-weak.js b/lib/rules/no-flow-weak.js deleted file mode 100644 index bcd9c96e..00000000 --- a/lib/rules/no-flow-weak.js +++ /dev/null @@ -1,24 +0,0 @@ -module.exports = { - meta: { - docs: {}, - schema: [] - }, - - create(context) { - function handleComment(comment) { - var value = comment.value.trim() - if (value.match(/@flow weak/)) { - context.report(comment, "Do not use Flow 'weak' mode checking, use @flow instead.") - } - } - - return { - LineComment: handleComment, - BlockComment: handleComment, - Program() { - const comments = context.getSourceCode().getAllComments() - comments.forEach(handleComment) - } - } - } -} diff --git a/lib/rules/no-noflow.js b/lib/rules/no-noflow.js deleted file mode 100644 index 4d8d35a3..00000000 --- a/lib/rules/no-noflow.js +++ /dev/null @@ -1,24 +0,0 @@ -module.exports = { - meta: { - docs: {}, - schema: [] - }, - - create(context) { - function handleComment(comment) { - var value = comment.value.trim() - if (value.match(/@noflow/)) { - context.report(comment, 'Do not disable Flow type checker, use @flow instead.') - } - } - - return { - LineComment: handleComment, - BlockComment: handleComment, - Program() { - const comments = context.getSourceCode().getAllComments() - comments.forEach(handleComment) - } - } - } -} diff --git a/package-lock.json b/package-lock.json index bd71bf4b..d26e2f2a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -780,14 +780,6 @@ "ignore": "^5.0.5" } }, - "eslint-plugin-flowtype": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-flowtype/-/eslint-plugin-flowtype-4.3.0.tgz", - "integrity": "sha512-elvqoadMHnYqSYN1YXn02DR7SFW8Kc2CLe8na3m2GdQPQhIY+BgCd2quVJ1AbW3aO0zcyE9loVJ7Szy8A/xlMA==", - "requires": { - "lodash": "^4.17.15" - } - }, "eslint-plugin-import": { "version": "2.18.2", "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.18.2.tgz", @@ -1008,12 +1000,6 @@ "integrity": "sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==", "dev": true }, - "flow-bin": { - "version": "0.110.1", - "resolved": "https://registry.npmjs.org/flow-bin/-/flow-bin-0.110.1.tgz", - "integrity": "sha512-6FhvNKNvPQ523mx7sqNxTQvI/HgAWa/pbIsQuCst53qRqs387EFfYqgm4I3Zae5HLaVFacBwgWKmjKd92vf19w==", - "dev": true - }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", diff --git a/package.json b/package.json index 2d94dbf0..0e9cd07d 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "eslint-github-init": "bin/eslint-github-init.js", "eslint-ignore-errors": "bin/eslint-ignore-errors.js", "eslint-unused-modules": "bin/eslint-unused-modules.js", - "flow-coverage": "bin/flow-coverage.js", "github-lint": "bin/github-lint.js", "npm-check-github-package-requirements": "bin/npm-check-github-package-requirements.js" }, @@ -38,7 +37,6 @@ "babel-eslint": ">=10.0.3", "eslint-config-prettier": ">=6.4.0", "eslint-plugin-eslint-comments": ">=3.0.1", - "eslint-plugin-flowtype": ">=4.3.0", "eslint-plugin-import": ">=2.18.2", "eslint-plugin-jsdoc": ">=15.5.2", "eslint-plugin-prettier": ">=2.6.0", @@ -50,8 +48,7 @@ "svg-element-attributes": ">=1.2.1" }, "peerDependencies": { - "eslint": ">=4.19.0", - "flow-bin": ">=0.70.0" + "eslint": ">=4.19.0" }, "files": [ "bin/*", @@ -60,7 +57,6 @@ ], "devDependencies": { "eslint": ">=6.5.1", - "flow-bin": ">=0.110.1", "mocha": ">=6.2.2", "rimraf": "^3.0.0" } diff --git a/tests/flow-to-typescript.js b/tests/flow-to-typescript.js deleted file mode 100644 index 89c38b0a..00000000 --- a/tests/flow-to-typescript.js +++ /dev/null @@ -1,19 +0,0 @@ -var rule = require('../lib/rules/flow-to-typescript') -var RuleTester = require('eslint').RuleTester - -var ruleTester = new RuleTester() - -ruleTester.run('flow-to-typescript', rule, { - valid: [{code: '/* @flow */'}, {code: '/* @flow weak */'}, {code: '/* @flow strict */'}, {code: '// @ts-check'}], - invalid: [ - { - code: '/* @closure-compiler */', - errors: [ - { - message: 'File must be type checked by TypeScript or Flow.', - type: 'Program' - } - ] - } - ] -}) diff --git a/tests/no-flow-weak.js b/tests/no-flow-weak.js deleted file mode 100644 index 2a8b5880..00000000 --- a/tests/no-flow-weak.js +++ /dev/null @@ -1,19 +0,0 @@ -var rule = require('../lib/rules/no-flow-weak') -var RuleTester = require('eslint').RuleTester - -var ruleTester = new RuleTester() - -ruleTester.run('no-flow-weak', rule, { - valid: [{code: '/* @flow */'}], - invalid: [ - { - code: '/* @flow weak */', - errors: [ - { - message: "Do not use Flow 'weak' mode checking, use @flow instead.", - type: 'Block' - } - ] - } - ] -}) diff --git a/tests/no-noflow.js b/tests/no-noflow.js deleted file mode 100644 index 8f86b825..00000000 --- a/tests/no-noflow.js +++ /dev/null @@ -1,19 +0,0 @@ -var rule = require('../lib/rules/no-noflow') -var RuleTester = require('eslint').RuleTester - -var ruleTester = new RuleTester() - -ruleTester.run('no-noflow', rule, { - valid: [{code: '/* @flow */'}], - invalid: [ - { - code: '/* @noflow */', - errors: [ - { - message: 'Do not disable Flow type checker, use @flow instead.', - type: 'Block' - } - ] - } - ] -})