diff --git a/package.json b/package.json index 2c09ee301..fbc0c8bad 100644 --- a/package.json +++ b/package.json @@ -57,8 +57,6 @@ "@commitlint/travis-cli": "^8.3.5", "@electron/get": "^1.10.0", "@polka/send-type": "^0.5.2", - "@typescript-eslint/eslint-plugin": "^3.3.0", - "@typescript-eslint/parser": "^3.3.0", "babel-loader": "^8.0.5", "buffer": "^5.6.0", "bytes": "^3.1.0", @@ -76,13 +74,8 @@ "dirty-chai": "^2.0.1", "documentation": "^13.0.1", "electron-mocha": "^8.2.0", - "eslint": "^6.3.0", - "eslint-config-standard": "^14.1.1", - "eslint-plugin-import": "^2.21.2", - "eslint-plugin-no-only-tests": "^2.4.0", - "eslint-plugin-node": "^11.0.0", - "eslint-plugin-promise": "^4.2.1", - "eslint-plugin-standard": "^4.0.1", + "eslint": "^6.8.0", + "eslint-config-ipfs": "^0.1.0", "execa": "^4.0.0", "extract-zip": "^2.0.1", "findup-sync": "^4.0.0", @@ -145,7 +138,7 @@ "not ie < 11" ], "eslintConfig": { - "extends": "./src/config/eslintrc.js" + "extends": "ipfs" }, "contributors": [ "dignifiedquire ", diff --git a/src/config/eslintrc-js.js b/src/config/eslintrc-js.js deleted file mode 100644 index 4d514c8d6..000000000 --- a/src/config/eslintrc-js.js +++ /dev/null @@ -1,51 +0,0 @@ -'use strict' - -module.exports = { - extends: 'standard', - parserOptions: { - sourceType: 'script' - }, - globals: { - self: true, - mocha: true - }, - plugins: [ - 'no-only-tests' - ], - rules: { - strict: [2, 'safe'], - curly: 'error', - 'block-scoped-var': 2, - complexity: 1, - 'default-case': 2, - 'dot-notation': 1, - 'guard-for-in': 1, - 'linebreak-style': [1, 'unix'], - 'no-alert': 2, - 'no-case-declarations': 2, - 'no-console': 2, - 'no-constant-condition': 2, - 'no-continue': 1, - 'no-div-regex': 2, - 'no-empty': 1, - 'no-empty-pattern': 2, - 'no-extra-semi': 2, - 'no-implicit-coercion': 2, - 'no-labels': 2, - 'no-loop-func': 2, - 'no-nested-ternary': 1, - 'no-only-tests/no-only-tests': 2, - 'no-script-url': 2, - 'no-warning-comments': 1, - 'quote-props': [2, 'as-needed'], - 'require-yield': 2, - 'max-nested-callbacks': [2, 4], - 'max-depth': [2, 4], - 'valid-jsdoc': [2, { - requireReturn: false, - requireParamDescription: false, - requireReturnDescription: false - }], - 'require-await': 2 - } -} diff --git a/src/config/eslintrc-ts.js b/src/config/eslintrc-ts.js deleted file mode 100644 index 3b60b9d44..000000000 --- a/src/config/eslintrc-ts.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict' -const { fromAegir } = require('../utils') -module.exports = { - parser: '@typescript-eslint/parser', - parserOptions: { - sourceType: 'module' - }, - plugins: ['@typescript-eslint'], - extends: [ - fromAegir('src/config/eslintrc-js.js'), - 'plugin:@typescript-eslint/recommended' - ] -} diff --git a/src/config/eslintrc.js b/src/config/eslintrc.js deleted file mode 100644 index fa8a08c39..000000000 --- a/src/config/eslintrc.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict' -const { fromAegir } = require('../utils') -module.exports = { - overrides: [ - { - files: [ - '**/*.js' - ], - extends: fromAegir('src/config/eslintrc-js.js') - }, - { - files: [ - '**/*.ts' - ], - extends: fromAegir('src/config/eslintrc-ts.js') - } - ] -} diff --git a/src/dependency-check.js b/src/dependency-check.js index f3eec88ce..a57a648a9 100644 --- a/src/dependency-check.js +++ b/src/dependency-check.js @@ -17,9 +17,9 @@ const defaultInput = [ /** * Check dependencies * - * @param {Object} argv - * @param {ExecaOptions} execaOptions - * @returns {ExecaChildProcess} + * @param {object} argv - Command line arguments passed to the process. + * @param {ExecaOptions} execaOptions - execa options. + * @returns {ExecaChildProcess} - Child process that does dependency check. */ const check = (argv = { _: [] }, execaOptions) => { const input = argv._.slice(1) diff --git a/src/docs/build.js b/src/docs/build.js index 733c56bde..eb06f0cd7 100644 --- a/src/docs/build.js +++ b/src/docs/build.js @@ -11,9 +11,9 @@ const { fromRoot, hasFile } = require('../utils') /** * Build docs * - * @param {Object} argv - * @param {ExecaOptions} execaOptions - * @returns {ExecaChildProcess} + * @param {object} argv - Command line arguments passed to the process. + * @param {ExecaOptions} execaOptions - execa options. + * @returns {ExecaChildProcess} - Child process that builds docs. */ const docs = (argv, execaOptions = {}) => { const forwardOptions = argv['--'] ? argv['--'] : [] diff --git a/src/lint.js b/src/lint.js index 06a10e235..cdbd0846e 100644 --- a/src/lint.js +++ b/src/lint.js @@ -83,7 +83,7 @@ function checkDependencyVersions () { function runLinter (opts = {}) { const cli = new CLIEngine({ useEslintrc: true, - baseConfig: require('./config/eslintrc.js'), + baseConfig: { extends: 'ipfs' }, fix: opts.fix }) diff --git a/src/utils.js b/src/utils.js index 8e1394081..d9c3b2c74 100644 --- a/src/utils.js +++ b/src/utils.js @@ -39,7 +39,7 @@ exports.fromAegir = (...p) => path.join(__dirname, '..', ...p) /** * Get package version * - * @returns {string} version + * @returns {string} - version */ exports.pkgVersion = async () => { const { @@ -51,36 +51,24 @@ exports.pkgVersion = async () => { /** * Gets the top level path of the project aegir is executed in. * - * @returns {string} + * @returns {string} - base path */ exports.getBasePath = () => { return process.cwd() } -/** - * @returns {string} - */ exports.getPathToPkg = () => { return path.join(exports.getBasePath(), PKG_FILE) } -/** - * @returns {string} - */ exports.getPathToDist = () => { return path.join(exports.getBasePath(), DIST_FOLDER) } -/** - * @returns {string} - */ exports.getUserConfigPath = () => { return findUp('.aegir.js') } -/** - * @returns {Object} - */ exports.getUserConfig = () => { let conf = {} try { @@ -98,9 +86,8 @@ exports.getUserConfig = () => { /** * Converts the given name from something like `peer-id` to `PeerId`. * - * @param {string} name - * - * @returns {string} + * @param {string} name - lib name in kebab + * @returns {string} - lib name in pascal */ exports.getLibraryName = (name) => { return pascalcase(name) @@ -108,8 +95,6 @@ exports.getLibraryName = (name) => { /** * Get the absolute path to `node_modules` for aegir itself - * - * @returns {string} */ exports.getPathToNodeModules = () => { return path.resolve(__dirname, '../node_modules') @@ -118,7 +103,7 @@ exports.getPathToNodeModules = () => { /** * Get the config for Listr. * - * @returns {Object} + * @returns {{renderer: 'verbose'}} - config for Listr */ exports.getListrConfig = () => { return { diff --git a/test/lint.js b/test/lint.js index 57302b6d4..efd2d34ca 100644 --- a/test/lint.js +++ b/test/lint.js @@ -8,15 +8,23 @@ const fs = require('fs') const rimraf = require('rimraf') const TEMP_FOLDER = path.join(__dirname, '../node_modules/.temp-test') -const setupProjectWithDeps = async (deps) => { + +const setupProject = async (project) => { const tmpDir = path.join(TEMP_FOLDER, `test-${Math.random()}`) await fs.promises.mkdir(tmpDir) - await fs.promises.writeFile(path.join(tmpDir, 'package.json'), JSON.stringify({ - name: 'my-project', - dependencies: deps - })) + for (const [name, content] of Object.entries(project)) { + await fs.promises.writeFile(path.join(tmpDir, name), content) + } process.chdir(tmpDir) } + +const setupProjectWithDeps = deps => setupProject({ + 'package.json': JSON.stringify({ + name: 'my-project', + dependencies: deps + }) +}) + const dependenciesShouldPassLinting = (deps) => { return setupProjectWithDeps(deps) .then(() => lint()) @@ -33,6 +41,24 @@ const dependenciesShouldFailLinting = (deps) => { }) } +const projectShouldPassLint = async (project) => { + await setupProject(project) + await lint() +} + +const projectShouldFailLint = async (project) => { + await setupProject(project) + let failed = false + try { + await lint({ silent: true }) + } catch (error) { + failed = true + expect(error.message).to.contain('Lint errors') + } + + expect(failed).to.equal(true, 'Should have failed!') +} + describe('lint', () => { const cwd = process.cwd() before(() => { @@ -166,4 +192,62 @@ describe('lint', () => { process.chdir(path.join(__dirname, './fixtures/js+ts/')) await lint() }) + + it('should pass if no .eslintrc found and does not follows ipfs eslint rules', async () => { + await projectShouldFailLint({ + 'package.json': JSON.stringify({ + name: 'no-config-fail', + main: 'index.js' + }), + 'index.js': '"use strict"\nmodule.exports = () => {}\n' + }) + }) + + it('should pass if no .eslintrc found but code follows ipfs eslint rules', async () => { + await projectShouldPassLint({ + 'package.json': JSON.stringify({ + name: 'no-config-fail', + main: 'index.js' + }), + 'index.js': '\'use strict\'\nmodule.exports = () => {}\n' + }) + }) + + it('should fail if .eslintrc overules ipfs and code does not follow it', async () => { + await projectShouldFailLint({ + 'package.json': JSON.stringify({ + name: 'with-config-fail', + main: 'index.js' + }), + 'index.js': '\'use strict\'\nmodule.exports = () => {}\n', + '.eslintrc': JSON.stringify({ + extends: 'ipfs', + rules: { + quotes: [ + 'error', + 'double' + ] + } + }) + }) + }) + + it('should pass if .eslintrc overules ipfs and code follows it', async () => { + await projectShouldPassLint({ + 'package.json': JSON.stringify({ + name: 'with-config-fail', + main: 'index.js' + }), + 'index.js': '"use strict"\nmodule.exports = () => {}\n', + '.eslintrc': JSON.stringify({ + extends: 'ipfs', + rules: { + quotes: [ + 'error', + 'double' + ] + } + }) + }) + }) })