Skip to content

Commit 0fb42b9

Browse files
authored
feat: factor eslint config to eslint-config-ipfs (#638)
1 parent b782b88 commit 0fb42b9

File tree

9 files changed

+104
-124
lines changed

9 files changed

+104
-124
lines changed

package.json

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@
5757
"@commitlint/travis-cli": "^8.3.5",
5858
"@electron/get": "^1.10.0",
5959
"@polka/send-type": "^0.5.2",
60-
"@typescript-eslint/eslint-plugin": "^3.3.0",
61-
"@typescript-eslint/parser": "^3.3.0",
6260
"babel-loader": "^8.0.5",
6361
"buffer": "^5.6.0",
6462
"bytes": "^3.1.0",
@@ -76,13 +74,8 @@
7674
"dirty-chai": "^2.0.1",
7775
"documentation": "^13.0.1",
7876
"electron-mocha": "^8.2.0",
79-
"eslint": "^6.3.0",
80-
"eslint-config-standard": "^14.1.1",
81-
"eslint-plugin-import": "^2.21.2",
82-
"eslint-plugin-no-only-tests": "^2.4.0",
83-
"eslint-plugin-node": "^11.0.0",
84-
"eslint-plugin-promise": "^4.2.1",
85-
"eslint-plugin-standard": "^4.0.1",
77+
"eslint": "^6.8.0",
78+
"eslint-config-ipfs": "^0.1.0",
8679
"execa": "^4.0.0",
8780
"extract-zip": "^2.0.1",
8881
"findup-sync": "^4.0.0",
@@ -145,7 +138,7 @@
145138
"not ie < 11"
146139
],
147140
"eslintConfig": {
148-
"extends": "./src/config/eslintrc.js"
141+
"extends": "ipfs"
149142
},
150143
"contributors": [
151144
"dignifiedquire <[email protected]>",

src/config/eslintrc-js.js

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/config/eslintrc-ts.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/config/eslintrc.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/dependency-check.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ const defaultInput = [
1717
/**
1818
* Check dependencies
1919
*
20-
* @param {Object} argv
21-
* @param {ExecaOptions} execaOptions
22-
* @returns {ExecaChildProcess}
20+
* @param {object} argv - Command line arguments passed to the process.
21+
* @param {ExecaOptions} execaOptions - execa options.
22+
* @returns {ExecaChildProcess} - Child process that does dependency check.
2323
*/
2424
const check = (argv = { _: [] }, execaOptions) => {
2525
const input = argv._.slice(1)

src/docs/build.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const { fromRoot, hasFile } = require('../utils')
1111
/**
1212
* Build docs
1313
*
14-
* @param {Object} argv
15-
* @param {ExecaOptions} execaOptions
16-
* @returns {ExecaChildProcess}
14+
* @param {object} argv - Command line arguments passed to the process.
15+
* @param {ExecaOptions} execaOptions - execa options.
16+
* @returns {ExecaChildProcess} - Child process that builds docs.
1717
*/
1818
const docs = (argv, execaOptions = {}) => {
1919
const forwardOptions = argv['--'] ? argv['--'] : []

src/lint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function checkDependencyVersions () {
8383
function runLinter (opts = {}) {
8484
const cli = new CLIEngine({
8585
useEslintrc: true,
86-
baseConfig: require('./config/eslintrc.js'),
86+
baseConfig: { extends: 'ipfs' },
8787
fix: opts.fix
8888
})
8989

src/utils.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ exports.fromAegir = (...p) => path.join(__dirname, '..', ...p)
3939
/**
4040
* Get package version
4141
*
42-
* @returns {string} version
42+
* @returns {string} - version
4343
*/
4444
exports.pkgVersion = async () => {
4545
const {
@@ -51,36 +51,24 @@ exports.pkgVersion = async () => {
5151
/**
5252
* Gets the top level path of the project aegir is executed in.
5353
*
54-
* @returns {string}
54+
* @returns {string} - base path
5555
*/
5656
exports.getBasePath = () => {
5757
return process.cwd()
5858
}
5959

60-
/**
61-
* @returns {string}
62-
*/
6360
exports.getPathToPkg = () => {
6461
return path.join(exports.getBasePath(), PKG_FILE)
6562
}
6663

67-
/**
68-
* @returns {string}
69-
*/
7064
exports.getPathToDist = () => {
7165
return path.join(exports.getBasePath(), DIST_FOLDER)
7266
}
7367

74-
/**
75-
* @returns {string}
76-
*/
7768
exports.getUserConfigPath = () => {
7869
return findUp('.aegir.js')
7970
}
8071

81-
/**
82-
* @returns {Object}
83-
*/
8472
exports.getUserConfig = () => {
8573
let conf = {}
8674
try {
@@ -98,18 +86,15 @@ exports.getUserConfig = () => {
9886
/**
9987
* Converts the given name from something like `peer-id` to `PeerId`.
10088
*
101-
* @param {string} name
102-
*
103-
* @returns {string}
89+
* @param {string} name - lib name in kebab
90+
* @returns {string} - lib name in pascal
10491
*/
10592
exports.getLibraryName = (name) => {
10693
return pascalcase(name)
10794
}
10895

10996
/**
11097
* Get the absolute path to `node_modules` for aegir itself
111-
*
112-
* @returns {string}
11398
*/
11499
exports.getPathToNodeModules = () => {
115100
return path.resolve(__dirname, '../node_modules')
@@ -118,7 +103,7 @@ exports.getPathToNodeModules = () => {
118103
/**
119104
* Get the config for Listr.
120105
*
121-
* @returns {Object}
106+
* @returns {{renderer: 'verbose'}} - config for Listr
122107
*/
123108
exports.getListrConfig = () => {
124109
return {

test/lint.js

Lines changed: 89 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,23 @@ const fs = require('fs')
88
const rimraf = require('rimraf')
99

1010
const TEMP_FOLDER = path.join(__dirname, '../node_modules/.temp-test')
11-
const setupProjectWithDeps = async (deps) => {
11+
12+
const setupProject = async (project) => {
1213
const tmpDir = path.join(TEMP_FOLDER, `test-${Math.random()}`)
1314
await fs.promises.mkdir(tmpDir)
14-
await fs.promises.writeFile(path.join(tmpDir, 'package.json'), JSON.stringify({
15-
name: 'my-project',
16-
dependencies: deps
17-
}))
15+
for (const [name, content] of Object.entries(project)) {
16+
await fs.promises.writeFile(path.join(tmpDir, name), content)
17+
}
1818
process.chdir(tmpDir)
1919
}
20+
21+
const setupProjectWithDeps = deps => setupProject({
22+
'package.json': JSON.stringify({
23+
name: 'my-project',
24+
dependencies: deps
25+
})
26+
})
27+
2028
const dependenciesShouldPassLinting = (deps) => {
2129
return setupProjectWithDeps(deps)
2230
.then(() => lint())
@@ -33,6 +41,24 @@ const dependenciesShouldFailLinting = (deps) => {
3341
})
3442
}
3543

44+
const projectShouldPassLint = async (project) => {
45+
await setupProject(project)
46+
await lint()
47+
}
48+
49+
const projectShouldFailLint = async (project) => {
50+
await setupProject(project)
51+
let failed = false
52+
try {
53+
await lint({ silent: true })
54+
} catch (error) {
55+
failed = true
56+
expect(error.message).to.contain('Lint errors')
57+
}
58+
59+
expect(failed).to.equal(true, 'Should have failed!')
60+
}
61+
3662
describe('lint', () => {
3763
const cwd = process.cwd()
3864
before(() => {
@@ -166,4 +192,62 @@ describe('lint', () => {
166192
process.chdir(path.join(__dirname, './fixtures/js+ts/'))
167193
await lint()
168194
})
195+
196+
it('should pass if no .eslintrc found and does not follows ipfs eslint rules', async () => {
197+
await projectShouldFailLint({
198+
'package.json': JSON.stringify({
199+
name: 'no-config-fail',
200+
main: 'index.js'
201+
}),
202+
'index.js': '"use strict"\nmodule.exports = () => {}\n'
203+
})
204+
})
205+
206+
it('should pass if no .eslintrc found but code follows ipfs eslint rules', async () => {
207+
await projectShouldPassLint({
208+
'package.json': JSON.stringify({
209+
name: 'no-config-fail',
210+
main: 'index.js'
211+
}),
212+
'index.js': '\'use strict\'\nmodule.exports = () => {}\n'
213+
})
214+
})
215+
216+
it('should fail if .eslintrc overules ipfs and code does not follow it', async () => {
217+
await projectShouldFailLint({
218+
'package.json': JSON.stringify({
219+
name: 'with-config-fail',
220+
main: 'index.js'
221+
}),
222+
'index.js': '\'use strict\'\nmodule.exports = () => {}\n',
223+
'.eslintrc': JSON.stringify({
224+
extends: 'ipfs',
225+
rules: {
226+
quotes: [
227+
'error',
228+
'double'
229+
]
230+
}
231+
})
232+
})
233+
})
234+
235+
it('should pass if .eslintrc overules ipfs and code follows it', async () => {
236+
await projectShouldPassLint({
237+
'package.json': JSON.stringify({
238+
name: 'with-config-fail',
239+
main: 'index.js'
240+
}),
241+
'index.js': '"use strict"\nmodule.exports = () => {}\n',
242+
'.eslintrc': JSON.stringify({
243+
extends: 'ipfs',
244+
rules: {
245+
quotes: [
246+
'error',
247+
'double'
248+
]
249+
}
250+
})
251+
})
252+
})
169253
})

0 commit comments

Comments
 (0)