Skip to content

Commit 6491eeb

Browse files
committed
fix lint
1 parent 3a1ced5 commit 6491eeb

9 files changed

Lines changed: 143 additions & 69 deletions

File tree

__tests__/index.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import fs from 'fs';
2-
import path from 'path';
3-
import os from 'os';
1+
import { execSync } from 'node:child_process';
2+
import fs from 'node:fs';
3+
import os from 'node:os';
4+
import path from 'node:path';
5+
import { fileURLToPath, URL } from 'node:url';
46
import nock from 'nock';
5-
import { URL, fileURLToPath } from 'url';
6-
import { execSync } from 'child_process';
77
import { runTests } from '../src/index.js';
88
import buildRoutes from '../src/routes.js';
99

@@ -26,18 +26,18 @@ it('runTests', async () => {
2626
language: 'ruby',
2727
},
2828
};
29-
nock(url.origin)
30-
.get(url.pathname)
31-
.query(true)
32-
.reply(200, result);
29+
nock(url.origin).get(url.pathname).query(true).reply(200, result);
3330

3431
const tmp = os.tmpdir();
3532
const mountPath = await fsp.mkdtemp(path.join(tmp, 'hexlet-project-'));
3633
const projectPath = await fsp.mkdtemp(path.join(tmp, 'hexlet-project-'));
3734
execSync(`cp -r ${projectFixture}/. ${projectPath}`);
3835

3936
await runTests({
40-
mountPath, projectPath, verbose: true, projectMemberId,
37+
mountPath,
38+
projectPath,
39+
verbose: true,
40+
projectMemberId,
4141
});
4242

4343
expect(true).toBe(true);

__tests__/packageChecker.test.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
import path from 'path';
2-
import { fileURLToPath } from 'url';
1+
import path from 'node:path';
2+
import { fileURLToPath } from 'node:url';
33

44
import checkPackageName from '../src/packageChecker.js';
55

66
const __filename = fileURLToPath(import.meta.url);
77
const __dirname = path.dirname(__filename);
88

9-
const verifiableProjects = [
10-
'javascript',
11-
'php',
12-
'python',
13-
];
9+
const verifiableProjects = ['javascript', 'php', 'python'];
1410

1511
// NOTE: Some projects are not packages.
1612
// Also, in some languages, verification is not needed,
@@ -24,33 +20,31 @@ const notVerifiableProjects = [
2420
undefined,
2521
];
2622

27-
const getFixturePath = (dirname) => (
28-
path.join(__dirname, '..', '__fixtures__', 'package_files', dirname)
29-
);
23+
const getFixturePath = (dirname) =>
24+
path.join(__dirname, '..', '__fixtures__', 'package_files', dirname);
3025

3126
describe('test projects with correct package name', () => {
3227
const codePath = getFixturePath('correct');
3328

3429
test.each(verifiableProjects)('%s', (sourceLang) => {
35-
expect(() => checkPackageName(codePath, sourceLang))
36-
.not.toThrow();
30+
expect(() => checkPackageName(codePath, sourceLang)).not.toThrow();
3731
});
3832
});
3933

4034
describe('test projects with wrong package name', () => {
4135
const codePath = getFixturePath('wrong');
4236

4337
test.each(verifiableProjects)('%s', (sourceLang) => {
44-
expect(() => checkPackageName(codePath, sourceLang))
45-
.toThrow(/^Package name should be .+ instead of wrong-package-name$/);
38+
expect(() => checkPackageName(codePath, sourceLang)).toThrow(
39+
/^Package name should be .+ instead of wrong-package-name$/,
40+
);
4641
});
4742
});
4843

4944
describe('test not verifiable projects', () => {
5045
const codePath = getFixturePath('correct');
5146

5247
test.each(notVerifiableProjects)('%s', (sourceLang) => {
53-
expect(() => checkPackageName(codePath, sourceLang))
54-
.not.toThrow();
48+
expect(() => checkPackageName(codePath, sourceLang)).not.toThrow();
5549
});
5650
});

bin/run-post-actions.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ const mountPath = core.getInput('mount-path', { required: true });
1212
const projectMemberId = core.getInput('hexlet-id', { required: true });
1313

1414
const params = {
15-
mountPath, projectMemberId, verbose,
15+
mountPath,
16+
projectMemberId,
17+
verbose,
1618
};
1719

1820
try {

bin/run-tests.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// @ts-check
44

5-
import path from 'path';
5+
import path from 'node:path';
66
import * as core from '@actions/core';
77
import cleanStack from 'clean-stack';
88

@@ -15,19 +15,27 @@ core.debug(process.cwd());
1515

1616
const mountPath = core.getInput('mount-path', { required: true });
1717
const verbose = core.getBooleanInput('verbose', { required: false });
18-
const projectPath = path.resolve(process.cwd(), process.env.ACTION_PROJECT_PATH || '');
18+
const projectPath = path.resolve(
19+
process.cwd(),
20+
process.env.ACTION_PROJECT_PATH || '',
21+
);
1922
const projectMemberId = core.getInput('hexlet-id', { required: true });
2023

2124
core.exportVariable('PWD', path.join(mountPath, 'source'));
2225

2326
const params = {
24-
projectPath, mountPath, verbose, projectMemberId,
27+
projectPath,
28+
mountPath,
29+
verbose,
30+
projectMemberId,
2531
};
2632

2733
try {
2834
await runTests(params);
2935
} catch (e) {
30-
core.error('The tests have failed. Examine what they have to say. Inhale deeply. Exhale. Fix the code.');
36+
core.error(
37+
'The tests have failed. Examine what they have to say. Inhale deeply. Exhale. Fix the code.',
38+
);
3139
// NOTE: бектрейс экшена пользователям не нужен
3240
if (!verbose) {
3341
e.stack = cleanStack(e.stack);

biome.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
3+
"vcs": {
4+
"enabled": true,
5+
"clientKind": "git",
6+
"useIgnoreFile": true
7+
},
8+
"files": {
9+
"ignoreUnknown": false,
10+
"includes": [
11+
"**",
12+
"!**/*.json",
13+
"!**/*.css",
14+
"!**/*.scss",
15+
"!test",
16+
"!public",
17+
"!app/assets/builds",
18+
"!app/javascript/routes.*",
19+
"!app/javascript/types/serializers",
20+
"!dist"
21+
]
22+
},
23+
"formatter": {
24+
"enabled": true,
25+
"indentStyle": "space"
26+
},
27+
"linter": {
28+
"enabled": true,
29+
"rules": {
30+
"recommended": true,
31+
"complexity": {
32+
"noBannedTypes": "off"
33+
},
34+
"correctness": {
35+
"noUnusedImports": "off",
36+
"noUnusedFunctionParameters": "off",
37+
"noUnusedVariables": "off"
38+
},
39+
"suspicious": {
40+
"noExplicitAny": "off"
41+
},
42+
"style": {
43+
"noNonNullAssertion": "off"
44+
}
45+
}
46+
},
47+
"javascript": {
48+
"formatter": {
49+
"quoteStyle": "single"
50+
}
51+
},
52+
"assist": {
53+
"enabled": true,
54+
"actions": {
55+
"source": {
56+
"organizeImports": "on"
57+
}
58+
}
59+
}
60+
}

server.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ import Fastify from 'fastify';
55
const fastify = Fastify({ logger: true });
66

77
// Declare a route
8-
fastify.get('/api/user_project_github_workflow/project_members/:id', async () => {
9-
const result = {
10-
tests_on: true,
11-
project: {
12-
image_name: 'hexlet-project-source-ci',
13-
},
14-
};
8+
fastify.get(
9+
'/api/user_project_github_workflow/project_members/:id',
10+
async () => {
11+
const result = {
12+
tests_on: true,
13+
project: {
14+
image_name: 'hexlet-project-source-ci',
15+
},
16+
};
1517

16-
return result;
17-
});
18+
return result;
19+
},
20+
);
1821

1922
// Run the server!
2023
const start = async () => {

src/index.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
// https://github.com/actions/javascript-action
44
// https://github.com/actions/toolkit/blob/master/docs/action-debugging.md
55

6-
import fs from 'fs';
7-
import path from 'path';
6+
import fs from 'node:fs';
7+
import path from 'node:path';
88
import { DefaultArtifactClient } from '@actions/artifact';
99
import * as core from '@actions/core';
10-
import * as io from '@actions/io';
1110
import * as exec from '@actions/exec';
11+
import * as glob from '@actions/glob';
1212
import { HttpClient } from '@actions/http-client';
13+
import * as io from '@actions/io';
1314
import colors from 'ansi-colors';
1415
import yaml from 'js-yaml';
15-
import * as glob from '@actions/glob';
16-
17-
import buildRoutes from './routes.js';
1816
import checkPackageName from './packageChecker.js';
17+
import buildRoutes from './routes.js';
1918

2019
const uploadArtifacts = async (diffpath) => {
2120
if (!fs.existsSync(diffpath)) {
@@ -59,9 +58,9 @@ const uploadTestData = async (options) => {
5958
return;
6059
}
6160

62-
const existPaths = artifacts.filter((artifactPath) => (
63-
fs.existsSync(path.join(projectSourcePath, artifactPath))
64-
));
61+
const existPaths = artifacts.filter((artifactPath) =>
62+
fs.existsSync(path.join(projectSourcePath, artifactPath)),
63+
);
6564

6665
if (existPaths.length === 0) {
6766
return;
@@ -75,7 +74,11 @@ const uploadTestData = async (options) => {
7574
const artifactName = 'test-data';
7675
const artifactClient = new DefaultArtifactClient();
7776
const archivePath = path.join(projectSourcePath, archiveName);
78-
await artifactClient.uploadArtifact(artifactName, [archivePath], projectSourcePath);
77+
await artifactClient.uploadArtifact(
78+
artifactName,
79+
[archivePath],
80+
projectSourcePath,
81+
);
7982
core.info(colors.bgYellow.black('Download snapshots from Artifacts.'));
8083
};
8184

@@ -101,7 +104,10 @@ const prepareProject = async (options) => {
101104
await exec.exec(copyCmd, null, cmdOptions);
102105
await io.mkdirP(codePath);
103106
await io.cp(`${projectPath}/.`, codePath, { recursive: true });
104-
await exec.exec('docker', ['build', '--cache-from', projectImageName, '.'], { ...cmdOptions, cwd: projectSourcePath });
107+
await exec.exec('docker', ['build', '--cache-from', projectImageName, '.'], {
108+
...cmdOptions,
109+
cwd: projectSourcePath,
110+
});
105111
};
106112

107113
const check = async ({ projectSourcePath, codePath, projectMember }) => {
@@ -110,7 +116,11 @@ const check = async ({ projectSourcePath, codePath, projectMember }) => {
110116
const options = { cwd: projectSourcePath };
111117
// NOTE: Installing dependencies is part of testing the project.
112118
await exec.exec('docker compose', ['run', 'app', 'make', 'setup'], options);
113-
await exec.exec('docker compose', ['-f', 'docker-compose.yml', 'up', '--abort-on-container-exit'], options);
119+
await exec.exec(
120+
'docker compose',
121+
['-f', 'docker-compose.yml', 'up', '--abort-on-container-exit'],
122+
options,
123+
);
114124

115125
const checkState = {
116126
state: 'success',
@@ -166,12 +176,7 @@ export const runPostActions = async (params) => {
166176
const { mountPath, projectMemberId, verbose } = params;
167177
const projectSourcePath = path.join(mountPath, 'source');
168178

169-
const diffpath = path.join(
170-
mountPath,
171-
'source',
172-
'tmp',
173-
'artifacts',
174-
);
179+
const diffpath = path.join(mountPath, 'source', 'tmp', 'artifacts');
175180

176181
const options = {
177182
projectSourcePath,

src/packageChecker.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// @ts-check
22

3-
import fs from 'fs';
4-
import path from 'path';
3+
import fs from 'node:fs';
4+
import path from 'node:path';
55
import ini from 'ini';
6+
67
// import yaml from 'js-yaml';
78
// import _ from 'lodash';
89

@@ -15,7 +16,8 @@ const parsers = {
1516
const getFullPath = (dirpath, filename) => path.resolve(dirpath, filename);
1617
const getFormat = (filepath) => path.extname(filepath).slice(1);
1718
const parse = (content, format) => parsers[format](content);
18-
const getData = (filepath) => parse(fs.readFileSync(filepath, 'utf-8'), getFormat(filepath));
19+
const getData = (filepath) =>
20+
parse(fs.readFileSync(filepath, 'utf-8'), getFormat(filepath));
1921

2022
const mapping = {
2123
python: {
@@ -28,15 +30,13 @@ const mapping = {
2830
},
2931
php: {
3032
expectedPackageName: 'hexlet/code',
31-
getPackageName: (codePath) => (
32-
getData(getFullPath(codePath, 'composer.json')).name
33-
),
33+
getPackageName: (codePath) =>
34+
getData(getFullPath(codePath, 'composer.json')).name,
3435
},
3536
javascript: {
3637
expectedPackageName: '@hexlet/code',
37-
getPackageName: (codePath) => (
38-
getData(getFullPath(codePath, 'package.json')).name
39-
),
38+
getPackageName: (codePath) =>
39+
getData(getFullPath(codePath, 'package.json')).name,
4040
},
4141
};
4242

@@ -53,7 +53,9 @@ const checkPackageName = (codePath, sourceLang) => {
5353
const packageName = getPackageName(codePath);
5454

5555
if (packageName !== expectedPackageName) {
56-
throw new Error(`Package name should be ${expectedPackageName} instead of ${packageName}`);
56+
throw new Error(
57+
`Package name should be ${expectedPackageName} instead of ${packageName}`,
58+
);
5759
}
5860
};
5961

src/routes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// TODO https://hexlet.io/api/user-project-github-workflow/projects/:slug/
2-
import path from 'path';
2+
import path from 'node:path';
33

44
const apiUrl = '/api/user_project_github_workflow/';
55

0 commit comments

Comments
 (0)