Skip to content

Commit

Permalink
Fix eslint (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuliren authored Feb 7, 2023
1 parent 5617e1b commit e776ab9
Show file tree
Hide file tree
Showing 11 changed files with 1,279 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .idea/stoat-action.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion action/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
"project": ["./tsconfig.json", "./tsconfig.test.json"]
},
"rules": {
"prettier/prettier": "off",
Expand Down
2 changes: 1 addition & 1 deletion action/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
moduleFileExtensions: ['js', 'ts'],
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.ts$': 'ts-jest'
'^.+\\.ts$': ['ts-jest', { tsconfig: './tsconfig.test.json' }]
},
collectCoverage: true,
verbose: true
Expand Down
5 changes: 5 additions & 0 deletions action/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*.ts", "src/**/*.json", "__tests__/**/*.test.ts"],
"exclude": ["node_modules"]
}
6 changes: 4 additions & 2 deletions cli/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
"project": ["./tsconfig.json", "./tsconfig.test.json"]
},
"rules": {
"prettier/prettier": "off",
Expand Down Expand Up @@ -51,7 +51,9 @@
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error",
"no-shadow": "off",
"@typescript-eslint/no-shadow": "error"
"@typescript-eslint/no-shadow": "error",
"no-console": "off",
"github/array-foreach": "warn"
},
"settings": {
"import/resolver": {
Expand Down
23 changes: 16 additions & 7 deletions cli/__tests__/stoatActionHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,29 @@ import { addStoatActionToYaml, isOnPushOrPull } from '../src/helpers/init/config

describe('Add Stoat Action to YAML', () => {
test('add action to build job', async () => {
expect(addStoatActionToYaml({ name: 'build', workflowFile: path.join(__dirname, 'example.yaml') })).toEqual(
fs.readFileSync(path.join(__dirname, 'expected-add-build.yaml')).toString()
);
expect(
addStoatActionToYaml({
name: 'build',
workflowFile: path.join(__dirname, 'example.yaml')
})
).toEqual(fs.readFileSync(path.join(__dirname, 'expected-add-build.yaml')).toString());
});

test('add action to build2 job', async () => {
expect(addStoatActionToYaml({ name: 'build2', workflowFile: path.join(__dirname, 'example.yaml') })).toEqual(
fs.readFileSync(path.join(__dirname, 'expected-add-build2.yaml')).toString()
);
expect(
addStoatActionToYaml({
name: 'build2',
workflowFile: path.join(__dirname, 'example.yaml')
})
).toEqual(fs.readFileSync(path.join(__dirname, 'expected-add-build2.yaml')).toString());
});

test('add action to both build and build2 jobs', async () => {
expect(
addStoatActionToYaml({ name: 'build2', workflowFile: path.join(__dirname, 'expected-add-build.yaml') })
addStoatActionToYaml({
name: 'build2',
workflowFile: path.join(__dirname, 'expected-add-build.yaml')
})
).toEqual(fs.readFileSync(path.join(__dirname, 'expected-add-build-and-build2.yaml')).toString());
});
});
Expand Down
2 changes: 1 addition & 1 deletion cli/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
moduleFileExtensions: ['js', 'ts'],
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.ts$': 'ts-jest'
'^.+\\.ts$': ['ts-jest', { tsconfig: './tsconfig.test.json' }]
},
collectCoverage: true,
verbose: true
Expand Down
3 changes: 3 additions & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
"@types/node": "^18.11.13",
"@vercel/ncc": "^0.36.0",
"esbuild": "^0.17.4",
"eslint": "^8.33.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-github": "^4.6.0",
"eslint-plugin-jest": "^27.2.1",
"husky": "^8.0.3",
"jest": "^29.3.1",
Expand Down
8 changes: 5 additions & 3 deletions cli/src/helpers/versionWarningBanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import latestVersion from 'latest-version';

import { version } from '../../package.json';

export default async function () {
export default async function main() {
try {
const latest = await latestVersion('stoat');

Expand All @@ -17,10 +17,12 @@ export default async function () {
'Please upgrade by running: npm update -g stoat'
];

if (compareVersions(version, latest!) < 0) {
if (compareVersions(version, latest) < 0) {
const longest = Math.max(...versionWarning.map((line) => line.length));
console.warn(chalk.yellow('-'.repeat(longest)));
versionWarning.forEach((line) => console.warn(chalk.yellow(`${line}`)));
for (const line of versionWarning) {
console.warn(chalk.yellow(`${line}`));
}
console.warn(chalk.yellow('-'.repeat(longest)));
console.warn();
}
Expand Down
5 changes: 5 additions & 0 deletions cli/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*.ts", "src/**/*.json", "__tests__/**/*.test.ts"],
"exclude": ["node_modules"]
}
Loading

0 comments on commit e776ab9

Please sign in to comment.