Skip to content

Commit ce4d6c1

Browse files
authored
chore: add eslinter, and run lint (#539)
* add eslinter, and run lint * add linter workflow
1 parent 1e8f248 commit ce4d6c1

32 files changed

+992
-474
lines changed

.github/workflows/lint-client.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Lint Client
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- release/*
8+
paths:
9+
- "clients/js/**"
10+
- ".github/workflows/lint-client.yml"
11+
pull_request:
12+
branches:
13+
- main
14+
paths:
15+
- "clients/js/**"
16+
- ".github/workflows/lint-client.yml"
17+
types: [opened, reopened]
18+
19+
workflow_dispatch:
20+
21+
jobs:
22+
starshipjs-tests:
23+
runs-on: ubuntu-latest
24+
25+
defaults:
26+
run:
27+
working-directory: clients/js
28+
29+
steps:
30+
- name: Checkout Repository 🛎️
31+
uses: actions/checkout@v4
32+
33+
- name: Setup Node.js
34+
uses: actions/setup-node@v4
35+
with:
36+
node-version: '20.x'
37+
38+
- name: Install Dependencies
39+
run: yarn install
40+
41+
- name: Build Project
42+
run: yarn build
43+
44+
- name: Run lint
45+
run: yarn run lint

clients/js/.prettierrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"trailingComma": "es5",
33
"tabWidth": 2,
44
"semi": true,
5-
"singleQuote": false
5+
"singleQuote": true
66
}

clients/js/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@
2727
"devDependencies": {
2828
"@types/jest": "^29.5.11",
2929
"@types/node": "^20.12.7",
30-
"@typescript-eslint/eslint-plugin": "^6.18.1",
31-
"@typescript-eslint/parser": "^6.18.1",
30+
"@typescript-eslint/eslint-plugin": "^7.17.0",
31+
"@typescript-eslint/parser": "^7.17.0",
32+
"babel-core": "7.0.0-bridge.0",
33+
"babel-jest": "^29.3.1",
3234
"copyfiles": "^2.4.1",
3335
"del-cli": "^5.1.0",
3436
"eslint": "^8.56.0",
3537
"eslint-config-prettier": "^9.1.0",
38+
"eslint-plugin-prettier": "^5.2.1",
3639
"eslint-plugin-simple-import-sort": "^10.0.0",
3740
"eslint-plugin-unused-imports": "^3.0.0",
3841
"jest": "^29.6.2",

clients/js/packages/cli/.eslintrc.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser', // Specify the ESLint parser
3+
plugins: ['@typescript-eslint', 'prettier'],
4+
extends: [
5+
'eslint:recommended',
6+
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
7+
'plugin:prettier/recommended'
8+
],
9+
parserOptions: {
10+
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
11+
sourceType: 'module', // Allows for the use of imports
12+
ecmaFeatures: {
13+
jsx: true // Allows for the parsing of JSX
14+
}
15+
},
16+
env: {
17+
es6: true,
18+
browser: true,
19+
node: true,
20+
jest: true
21+
},
22+
rules: {
23+
'@typescript-eslint/no-explicit-any': 'off', // Disable the rule entirely
24+
'no-debugger': 2,
25+
'no-alert': 2,
26+
'no-await-in-loop': 0,
27+
'no-prototype-builtins': 0,
28+
'no-return-assign': ['error', 'except-parens'],
29+
'no-restricted-syntax': [
30+
2,
31+
'ForInStatement',
32+
'LabeledStatement',
33+
'WithStatement'
34+
],
35+
'no-unused-vars': [
36+
0,
37+
{
38+
ignoreSiblings: true,
39+
argsIgnorePattern: 'React|res|next|^_'
40+
}
41+
],
42+
'prefer-const': [
43+
'error',
44+
{
45+
destructuring: 'all'
46+
}
47+
],
48+
'no-unused-expressions': [
49+
2,
50+
{
51+
allowTaggedTemplates: true
52+
}
53+
],
54+
'no-console': 'off',
55+
'comma-dangle': 2,
56+
'jsx-quotes': [2, 'prefer-double'],
57+
'linebreak-style': ['error', 'unix'],
58+
quotes: [
59+
2,
60+
'single',
61+
{
62+
avoidEscape: true,
63+
allowTemplateLiterals: true
64+
}
65+
],
66+
'prettier/prettier': [
67+
'error',
68+
{
69+
trailingComma: 'none',
70+
singleQuote: true,
71+
printWidth: 80
72+
}
73+
]
74+
}
75+
};
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/** @type {import('ts-jest').JestConfigWithTsJest} */
22
module.exports = {
3-
preset: "ts-jest",
4-
testEnvironment: "node",
5-
transform: {
6-
"^.+\\.tsx?$": [
7-
"ts-jest",
8-
{
9-
babelConfig: false,
10-
tsconfig: "tsconfig.json",
11-
},
12-
],
13-
},
14-
transformIgnorePatterns: [`/node_modules/*`],
15-
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
16-
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
17-
modulePathIgnorePatterns: ["dist/*"]
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
transform: {
6+
'^.+\\.tsx?$': [
7+
'ts-jest',
8+
{
9+
babelConfig: false,
10+
tsconfig: 'tsconfig.json'
11+
}
12+
]
13+
},
14+
transformIgnorePatterns: [`/node_modules/*`],
15+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
16+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
17+
modulePathIgnorePatterns: ['dist/*']
1818
};

clients/js/packages/cli/src/index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import { StarshipClient, StarshipInstaller } from '@starship-ci/client'; // Adju
33
import { Inquirerer, type Question } from 'inquirerer';
44
import minimist from 'minimist';
55

6-
import { displayUsage, displayVersion, loadConfig, params,usageText } from './utils';
6+
import {
7+
displayUsage,
8+
displayVersion,
9+
loadConfig,
10+
params,
11+
usageText
12+
} from './utils';
713

814
const argv = minimist(process.argv.slice(2), {
915
alias: {
@@ -24,11 +30,11 @@ const prompter = new Inquirerer({
2430
noTty: !argv.tty
2531
});
2632

27-
const questions: Question[] = params.map(name => ({ name, type: 'text' }));
33+
const questions: Question[] = params.map((name) => ({ name, type: 'text' }));
2834

2935
// Filter questions based on the command
3036
function getQuestionsForCommand(command: string): Question[] {
31-
const commonQuestions = questions.filter(q => q.name !== 'config');
37+
const commonQuestions = questions.filter((q) => q.name !== 'config');
3238
if (['start', 'deploy', 'start-ports', 'wait-for-pods'].includes(command)) {
3339
return questions; // Include all questions, including config
3440
} else {
@@ -63,8 +69,8 @@ async function main() {
6369
switch (command) {
6470
case 'install':
6571
installer.checkAndInstallDependencies().catch((err: any) => {
66-
console.error('An error occurred during start:', err);
67-
process.exit(1);
72+
console.error('An error occurred during start:', err);
73+
process.exit(1);
6874
});
6975
break;
7076
case 'start':
@@ -112,7 +118,7 @@ async function main() {
112118
}
113119

114120
// Improved error handling
115-
main().catch(err => {
121+
main().catch((err) => {
116122
console.error('An error occurred:', err);
117123
prompter.close();
118124
process.exit(1);

clients/js/packages/cli/src/package.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { existsSync,readFileSync } from "fs";
2-
import { dirname,join } from "path";
1+
import { existsSync, readFileSync } from 'fs';
2+
import { dirname, join } from 'path';
33

4-
// need to search due to the dist/ folder and src/, etc.
4+
// need to search due to the dist/ folder and src/, etc.
55
function findPackageJson(currentDir: string): any {
66
const filePath = join(currentDir, 'package.json');
77

@@ -30,4 +30,4 @@ export function readAndParsePackageJson() {
3030
const str = readFileSync(pkgPath, 'utf8');
3131
const pkg = JSON.parse(str);
3232
return pkg;
33-
}
33+
}

clients/js/packages/cli/src/prompt.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,18 @@ export class Inquirerer {
2222
}
2323

2424
// Method to prompt for missing parameters
25-
public async prompt<T extends object>(params: T, questions: Question[], usageText?: string): Promise<T> {
25+
public async prompt<T extends object>(
26+
params: T,
27+
questions: Question[],
28+
usageText?: string
29+
): Promise<T> {
2630
const obj: any = { ...params };
2731

28-
if (usageText && Object.values(params).some(value => value === undefined) && !this.noTty) {
32+
if (
33+
usageText &&
34+
Object.values(params).some((value) => value === undefined) &&
35+
!this.noTty
36+
) {
2937
console.log(usageText);
3038
}
3139

@@ -37,7 +45,9 @@ export class Inquirerer {
3745
this.rl.question(`Enter ${question.name}: `, resolve);
3846
});
3947
} else {
40-
throw new Error("No TTY available and a readline interface is missing.");
48+
throw new Error(
49+
'No TTY available and a readline interface is missing.'
50+
);
4151
}
4252
} else {
4353
// Optionally handle noTty cases, e.g., set defaults or throw errors

clients/js/packages/cli/src/utils.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
1-
import {defaultStarshipContext, StarshipConfig, StarshipContext} from '@starship-ci/client'; // Adjust the import path as necessary
1+
import {
2+
defaultStarshipContext,
3+
StarshipConfig,
4+
StarshipContext
5+
} from '@starship-ci/client'; // Adjust the import path as necessary
26
import chalk from 'chalk';
3-
import {readFileSync} from 'fs';
7+
import { readFileSync } from 'fs';
48
import * as yaml from 'js-yaml';
5-
import { resolve} from 'path';
9+
import { resolve } from 'path';
610

7-
import {readAndParsePackageJson} from './package';
11+
import { readAndParsePackageJson } from './package';
812

913
// Function to display the version information
1014
export function displayVersion() {
11-
const pkg = readAndParsePackageJson();
12-
console.log(chalk.green(`Name: ${pkg.name}`));
13-
console.log(chalk.blue(`Version: ${pkg.version}`));
15+
const pkg = readAndParsePackageJson();
16+
console.log(chalk.green(`Name: ${pkg.name}`));
17+
console.log(chalk.blue(`Version: ${pkg.version}`));
1418
}
1519

16-
1720
const resolvePath = (filename: string) =>
1821
filename.startsWith('/') ? filename : resolve((process.cwd(), filename));
1922

20-
2123
const loadYaml = (filename: string): any => {
2224
const path = resolvePath(filename);
2325
const fileContents = readFileSync(path, 'utf8');
2426
return yaml.load(fileContents);
25-
}
27+
};
2628

2729
export interface Config {
28-
context: StarshipContext,
29-
starship: StarshipConfig
30+
context: StarshipContext;
31+
starship: StarshipConfig;
3032
}
3133

3234
export const params: string[] = [
@@ -36,36 +38,38 @@ export const params: string[] = [
3638
'repo',
3739
'repoUrl',
3840
'chart',
39-
'namespace',
40-
]
41+
'namespace'
42+
];
4143

4244
export const loadConfig = (argv: any): Config => {
43-
console.log("argv: ", argv);
44-
let context: StarshipContext = { ...defaultStarshipContext } as StarshipContext;
45+
console.log('argv: ', argv);
46+
const context: StarshipContext = {
47+
...defaultStarshipContext
48+
} as StarshipContext;
4549
let starship: StarshipConfig = {} as StarshipConfig;
4650

47-
console.log("context", context);
51+
console.log('context', context);
4852

4953
// Override context with command-line arguments dynamically based on StarshipContext keys
50-
params.forEach(key => {
54+
params.forEach((key) => {
5155
if (argv[key] !== undefined) {
52-
console.log("key: ", key, " argv[key]: ", argv[key]);
53-
// @ts-ignore
56+
console.log('key: ', key, ' argv[key]: ', argv[key]);
57+
// @ts-expect-error - dynamic assignment
5458
context[key] = argv[key];
5559
}
5660
});
5761

5862
if (context.config) {
5963
context.config = resolvePath(context.config);
60-
starship = loadYaml(context.config) as StarshipConfig
64+
starship = loadYaml(context.config) as StarshipConfig;
6165
}
6266

63-
console.log("starship: ", starship);
67+
console.log('starship: ', starship);
6468

65-
return {context, starship};
66-
}
69+
return { context, starship };
70+
};
6771

68-
export const usageText =`
72+
export const usageText = `
6973
Usage: starship <command> [options]
7074
7175
Commands:
@@ -106,4 +110,4 @@ Additional Help:
106110

107111
export function displayUsage() {
108112
console.log(usageText);
109-
};
113+
}

0 commit comments

Comments
 (0)