Skip to content
This repository was archived by the owner on Jan 10, 2021. It is now read-only.

Commit 51fdbbb

Browse files
committed
lint
1 parent c801353 commit 51fdbbb

File tree

7 files changed

+96
-81
lines changed

7 files changed

+96
-81
lines changed

.eslintrc.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
"env": {
3+
"browser": true,
4+
"node": true,
5+
"es6": true
6+
},
7+
"extends": "eslint:recommended",
8+
"globals": {
9+
"Atomics": "readonly",
10+
"SharedArrayBuffer": "readonly"
11+
},
12+
"parserOptions": {
13+
"ecmaVersion": 2018,
14+
"sourceType": "module"
15+
},
16+
"rules": {
17+
}
18+
};

__tests__/integration.test.js

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,52 @@
1-
import path from 'path'
2-
import { exec } from 'child_process'
3-
import { promisify } from 'util'
4-
import { init } from './../src/index'
5-
import { shouldHideMessage } from '../src/utils/misc';
1+
import path from "path";
2+
import { exec } from "child_process";
3+
import { promisify } from "util";
4+
import { init } from "./../src/index";
5+
import { shouldHideMessage } from "../src/utils/misc";
66

7-
describe('Integration test', () => {
8-
const pkgPath = path.resolve('__tests__/fixtures/pkg');
7+
describe("Integration test", () => {
8+
const pkgPath = path.resolve("__tests__/fixtures/pkg");
99

10-
const consolelog = global.console.log
10+
const consolelog = global.console.log;
1111

12-
it('prints everything', async () => {
13-
14-
let log = ''
12+
it("prints everything", async () => {
13+
let log = "";
1514
console.log = jest.fn().mockImplementation((str1, str2) => {
16-
log += str1 + str2
17-
})
15+
log += str1 + str2;
16+
});
1817

19-
await init(pkgPath, false)
18+
await init(pkgPath, false);
2019

21-
console.log = consolelog
20+
console.log = consolelog;
2221
const content = [
23-
'Thanks for installing pkg',
24-
'Please consider donating to help us maintain this package.',
25-
'GitHub',
26-
'https://github.com/users/Jack/sponsorship',
27-
'Patreon',
28-
'https://patreon.com/Jack',
29-
'Open Collective'
30-
]
22+
"Thanks for installing pkg",
23+
"Please consider donating to help us maintain this package.",
24+
"GitHub",
25+
"https://github.com/users/Jack/sponsorship",
26+
"Patreon",
27+
"https://patreon.com/Jack",
28+
"Open Collective"
29+
];
3130

3231
content.forEach(sentence => {
33-
expect(log.includes(sentence)).toBe(true)
34-
})
35-
})
36-
32+
expect(log.includes(sentence)).toBe(true);
33+
});
34+
});
35+
36+
it("returns expected result on postinstall script", async () => {
37+
process.env.GITHUB_SPONSORS_FORCE = true;
38+
const { stdout: rawStdout } = await promisify(exec)("npm run postinstall", {
39+
cwd: pkgPath,
40+
env: process.env
41+
});
42+
const stdout = rawStdout.toString("utf8");
3743

38-
it('returns expected result on postinstall script', async () => {
39-
process.env.GITHUB_SPONSORS_FORCE = true
40-
const { stdout: rawStdout } = await promisify(exec)('npm run postinstall', { cwd: pkgPath, env: process.env })
41-
const stdout = rawStdout.toString('utf8')
42-
4344
const content = [
44-
'Thanks for installing pkg',
45-
'Please consider donating to help us maintain this package.'
46-
]
45+
"Thanks for installing pkg",
46+
"Please consider donating to help us maintain this package."
47+
];
4748
content.forEach(sentence => {
48-
expect(stdout.includes(sentence)).toBe(true)
49-
})
50-
})
51-
52-
53-
})
49+
expect(stdout.includes(sentence)).toBe(true);
50+
});
51+
});
52+
});

__tests__/misc.test.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,43 @@
1-
import {shouldHideMessage} from './../src/utils/misc'
2-
3-
describe('shouldHideMessage()', () => {
1+
import { shouldHideMessage } from "./../src/utils/misc";
42

3+
describe("shouldHideMessage()", () => {
54
// Force message
6-
;[1, true].forEach(truthy => {
5+
[1, true].forEach(truthy => {
76
it(`should not hide message when GITHUB_SPONSORS_FORCE is set to ${truthy}`, () => {
8-
const env = { GITHUB_SPONSORS_FORCE: truthy}
7+
const env = { GITHUB_SPONSORS_FORCE: truthy };
98
expect(shouldHideMessage(env)).toBe(false);
10-
})
11-
})
9+
});
10+
});
1211

1312
// Oracle postinstall
14-
;[1, true].forEach(truthy => {
13+
[1, true].forEach(truthy => {
1514
it(`should hide message when OC_POSTINSTALL_TEST is set to ${truthy}`, () => {
16-
const env = { OC_POSTINSTALL_TEST: truthy }
15+
const env = { OC_POSTINSTALL_TEST: truthy };
1716
expect(shouldHideMessage(env)).toBe(true);
18-
})
19-
})
17+
});
18+
});
2019

2120
// CI with CI env
22-
;[1, true].forEach(truthy => {
21+
[1, true].forEach(truthy => {
2322
it(`should hide message when CI is set to ${truthy}`, () => {
24-
const env = { CI: truthy }
23+
const env = { CI: truthy };
2524
expect(shouldHideMessage(env)).toBe(true);
26-
})
27-
})
25+
});
26+
});
2827

2928
// CI with CONTINUOUS_INTEGRATION env
30-
;[1, true].forEach(truthy => {
29+
[1, true].forEach(truthy => {
3130
it(`should hide message when CONTINUOUS_INTEGRATION is set to ${truthy}`, () => {
32-
const env = { CONTINUOUS_INTEGRATION: truthy }
31+
const env = { CONTINUOUS_INTEGRATION: truthy };
3332
expect(shouldHideMessage(env)).toBe(true);
34-
})
35-
})
33+
});
34+
});
3635

3736
// Dev environment
38-
;['test', 'production'].forEach(nodeEnv => {
37+
["test", "production"].forEach(nodeEnv => {
3938
it(`should hide message when node environment is not development`, () => {
40-
const env = { NODE_ENV: nodeEnv }
39+
const env = { NODE_ENV: nodeEnv };
4140
expect(shouldHideMessage(env)).toBe(true);
42-
})
43-
})
44-
45-
})
41+
});
42+
});
43+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"dev": "rollup -c rollup.config.js -w",
1616
"build": "rollup -c rollup.config.js",
1717
"prettier": "prettier --no-config --write '{src,__{tests,mocks}__}/**/*.js'",
18-
"lint": "eslint",
18+
"lint": "eslint src/",
1919
"justatest": "./bin/github-sponsors.js",
2020
"docs:dev": "vuepress dev docs",
2121
"docs:build": "vuepress build docs"

src/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
/* eslint-disable no-console */
2+
13
import { parseFundingFile } from "./utils/parse";
24
import { printDonationMessage } from "./utils/print";
35
import { shouldHideMessage } from "./utils/misc";
46

5-
export async function init(path = process.cwd(), hideMessage = shouldHideMessage()) {
7+
export async function init(
8+
path = process.cwd(),
9+
hideMessage = shouldHideMessage()
10+
) {
611
if (hideMessage) return;
712
try {
813
const fundingConfig = await parseFundingFile(path);
9-
printDonationMessage(
10-
fundingConfig,
11-
path
12-
);
14+
printDonationMessage(fundingConfig, path);
1315
} catch (e) {
1416
console.error(e);
1517
}

src/utils/parse.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import fs from "fs";
22
import { promisify } from "util";
3-
import path from "path";
43
import YAML from "yaml";
54

65
const readFile = promisify(fs.readFile);
@@ -10,10 +9,9 @@ const FUNDING_FILENAME = "FUNDING.yml";
109

1110
// Parse the FUNDING.yml and return the content
1211
export const parseFundingFile = async (path = process.cwd()) => {
13-
let isFileExist = false;
1412
const pathToFile = `${path}/.github/${FUNDING_FILENAME}`;
1513
try {
16-
isFileExist = await access(pathToFile, fs.constants.R_OK);
14+
await access(pathToFile, fs.constants.R_OK);
1715
} catch (e) {
1816
throw new Error("FUNDING.yml file not found");
1917
}

src/utils/print.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
/* eslint-disable no-console */
2+
/* eslint-disable no-control-regex */
3+
14
import { execSync } from "child_process";
2-
import path from 'path';
35
import chalk from "chalk";
6+
import path from "path";
47

58
// from nuxt/opencollective
69

@@ -36,11 +39,8 @@ export const print = (color = null) => (str = "") => {
3639
console.log(leftPadding, str);
3740
};
3841

39-
export const printDonationMessage = (
40-
fundingConfig,
41-
pkgPath
42-
) => {
43-
const packageJson = require(path.resolve(pkgPath) + '/package.json');
42+
export const printDonationMessage = (fundingConfig, pkgPath) => {
43+
const packageJson = require(path.resolve(pkgPath) + "/package.json");
4444
const dim = print("dim");
4545
const yellow = print("yellow");
4646
const emptyLine = print();

0 commit comments

Comments
 (0)