@fullstacksjs/eslint-config 7.1.0 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +9 -0
- package/bin/lib/createOptions.js +25 -0
- package/bin/lib/generateFile.js +15 -0
- package/bin/lib/getUserInput.js +24 -0
- package/bin/lib/parseArgs.js +12 -0
- package/bin/lib/tasks.js +27 -0
- package/package.json +10 -3
- package/rules/strict.js +5 -1
- package/rules/typescript.js +52 -0
package/bin/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const getUserInput = require('./getUserInput');
|
|
2
|
+
const args = require('./parseArgs');
|
|
3
|
+
|
|
4
|
+
const eslintrcConfig = {
|
|
5
|
+
extends: ['@fullstacksjs'],
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const requiredPackages = ['@fullstacksjs/eslint-config', 'eslint', 'prettier'];
|
|
9
|
+
|
|
10
|
+
async function createOptions() {
|
|
11
|
+
const isTechnologyInArgv = args.t != null;
|
|
12
|
+
const optionsFromArgs = { technology: args.t };
|
|
13
|
+
const userInput = isTechnologyInArgv ? optionsFromArgs : await getUserInput();
|
|
14
|
+
|
|
15
|
+
if (userInput.language === 'ts') {
|
|
16
|
+
requiredPackages.push('typescript');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
eslintrc: eslintrcConfig,
|
|
21
|
+
packages: requiredPackages,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = createOptions;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const { writeFile } = require('fs/promises');
|
|
2
|
+
|
|
3
|
+
function createFileTask(eslintrc, ctx, task) {
|
|
4
|
+
return writeFile('.eslintrc', JSON.stringify(eslintrc, null, 2))
|
|
5
|
+
.then(() => {
|
|
6
|
+
task.title = `.eslintrc - Successfully Generated.`;
|
|
7
|
+
})
|
|
8
|
+
.catch(() => {
|
|
9
|
+
ctx.isEslintrc = false;
|
|
10
|
+
task.title = `Generating .eslintrc file`;
|
|
11
|
+
throw Error("Couldn't create file");
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = createFileTask;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const inquirer = require('inquirer');
|
|
2
|
+
|
|
3
|
+
function getUserInput() {
|
|
4
|
+
return inquirer.prompt([
|
|
5
|
+
{
|
|
6
|
+
type: 'list',
|
|
7
|
+
name: 'language',
|
|
8
|
+
message: 'which technology are you using?',
|
|
9
|
+
choices: [
|
|
10
|
+
{
|
|
11
|
+
value: 'ts',
|
|
12
|
+
name: 'ESLint alongside TypeScript',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
value: 'js',
|
|
16
|
+
name: 'ESLint for JavaScript development',
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
default: 'js',
|
|
20
|
+
},
|
|
21
|
+
]);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = getUserInput;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const yargs = require('yargs');
|
|
2
|
+
|
|
3
|
+
const args = yargs(process.argv.slice(2))
|
|
4
|
+
.alias('t', 'technology')
|
|
5
|
+
.describe('t', 'Which technology are you using')
|
|
6
|
+
.choices('t', ['ts', 'js'])
|
|
7
|
+
.usage('Usage: $0 [-t ts|js]')
|
|
8
|
+
.example('$0 - ts')
|
|
9
|
+
.help('h')
|
|
10
|
+
.alias('h', 'help').argv;
|
|
11
|
+
|
|
12
|
+
module.exports = args;
|
package/bin/lib/tasks.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const Listr = require('listr');
|
|
2
|
+
const util = require('util');
|
|
3
|
+
const exec = util.promisify(require('child_process').exec);
|
|
4
|
+
const createFileTask = require('./generateFile');
|
|
5
|
+
|
|
6
|
+
function createTasks({ packages, eslintrc }) {
|
|
7
|
+
const installTasks = packages.map(pkg => ({
|
|
8
|
+
title: `Installing ${pkg}`,
|
|
9
|
+
task: (ctx, task) => exec(`npm i -D ${pkg}`).then(() => (task.title = `${pkg} Installed`)),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
return new Listr(
|
|
13
|
+
[
|
|
14
|
+
{
|
|
15
|
+
title: 'Installing dependencies using npm',
|
|
16
|
+
task: () => new Listr(installTasks, { exitOnError: true }),
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
title: 'Generating .eslintrc file',
|
|
20
|
+
task: (ctx, task) => createFileTask(eslintrc, ctx, task),
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
{ exitOnError: false },
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = createTasks;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fullstacksjs/eslint-config",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "fullstacks <fullstacksjs@gmail.com>",
|
|
6
6
|
"description": "fullstacks eslint config",
|
|
@@ -11,7 +11,11 @@
|
|
|
11
11
|
"publishConfig": {
|
|
12
12
|
"registry": "https://registry.npmjs.org"
|
|
13
13
|
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"fullstacksjs-eslint": "./bin/index.js"
|
|
16
|
+
},
|
|
14
17
|
"files": [
|
|
18
|
+
"bin",
|
|
15
19
|
"rules",
|
|
16
20
|
"base.js",
|
|
17
21
|
"index.js",
|
|
@@ -61,12 +65,15 @@
|
|
|
61
65
|
"eslint": "8.5.0",
|
|
62
66
|
"eslint-find-rules": "4.0.0",
|
|
63
67
|
"husky": "7.0.4",
|
|
64
|
-
"
|
|
68
|
+
"inquirer": "8.2.0",
|
|
69
|
+
"lint-staged": "12.1.2",
|
|
70
|
+
"listr": "0.14.3",
|
|
65
71
|
"np": "7.6.0",
|
|
66
72
|
"npm-run-all": "4.1.5",
|
|
67
73
|
"pinst": "2.1.6",
|
|
68
74
|
"prettier": "2.5.1",
|
|
69
|
-
"typescript": "4.5.4"
|
|
75
|
+
"typescript": "4.5.4",
|
|
76
|
+
"yargs": "17.3.1"
|
|
70
77
|
},
|
|
71
78
|
"peerDependencies": {
|
|
72
79
|
"cypress": ">=8",
|
package/rules/strict.js
CHANGED
|
@@ -16,6 +16,10 @@ module.exports = {
|
|
|
16
16
|
selector: 'default',
|
|
17
17
|
format: ['camelCase'],
|
|
18
18
|
},
|
|
19
|
+
{
|
|
20
|
+
selector: 'function',
|
|
21
|
+
format: ['camelCase', 'PascalCase'],
|
|
22
|
+
},
|
|
19
23
|
// variables, CONSTANTS, ReactComponents
|
|
20
24
|
{
|
|
21
25
|
selector: 'variable',
|
|
@@ -23,7 +27,7 @@ module.exports = {
|
|
|
23
27
|
},
|
|
24
28
|
{
|
|
25
29
|
selector: 'parameter',
|
|
26
|
-
format: ['camelCase'],
|
|
30
|
+
format: ['camelCase', 'PascalCase'],
|
|
27
31
|
leadingUnderscore: 'allow',
|
|
28
32
|
},
|
|
29
33
|
{
|
package/rules/typescript.js
CHANGED
|
@@ -29,6 +29,58 @@ module.exports = {
|
|
|
29
29
|
'@typescript-eslint/member-naming': 'off',
|
|
30
30
|
'@typescript-eslint/member-ordering': 'off',
|
|
31
31
|
'@typescript-eslint/method-signature-style': ['warn', 'property'],
|
|
32
|
+
'@typescript-eslint/naming-convention': [
|
|
33
|
+
'warn',
|
|
34
|
+
{
|
|
35
|
+
selector: 'default',
|
|
36
|
+
format: ['camelCase'],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
selector: 'function',
|
|
40
|
+
format: ['camelCase', 'PascalCase'],
|
|
41
|
+
},
|
|
42
|
+
// variables, CONSTANTS, ReactComponents
|
|
43
|
+
{
|
|
44
|
+
selector: 'variable',
|
|
45
|
+
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
selector: 'parameter',
|
|
49
|
+
format: ['camelCase', 'PascalCase'],
|
|
50
|
+
leadingUnderscore: 'allow',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
selector: 'memberLike',
|
|
54
|
+
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
|
|
55
|
+
leadingUnderscore: 'allow',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
selector: 'memberLike',
|
|
59
|
+
modifiers: ['static'],
|
|
60
|
+
format: ['camelCase', 'PascalCase'],
|
|
61
|
+
leadingUnderscore: 'allow',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
selector: 'memberLike',
|
|
65
|
+
modifiers: ['private'],
|
|
66
|
+
format: ['camelCase'],
|
|
67
|
+
leadingUnderscore: 'allow',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
selector: 'typeLike',
|
|
71
|
+
format: ['PascalCase'],
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
selector: 'enumMember',
|
|
75
|
+
format: ['PascalCase'],
|
|
76
|
+
},
|
|
77
|
+
// disallow I prefix for interfaces
|
|
78
|
+
{
|
|
79
|
+
selector: 'interface',
|
|
80
|
+
format: ['PascalCase'],
|
|
81
|
+
custom: { regex: '^I[A-Z]', match: false },
|
|
82
|
+
},
|
|
83
|
+
],
|
|
32
84
|
'@typescript-eslint/no-array-constructor': 'error',
|
|
33
85
|
'@typescript-eslint/no-base-to-string': 'off', // false negative
|
|
34
86
|
'@typescript-eslint/no-confusing-non-null-assertion': 'error',
|