Skip to content

Commit 997f80c

Browse files
committed
wip: fix lints
1 parent 6e14182 commit 997f80c

16 files changed

+234
-113
lines changed

.mocharc.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
process.env.TS_NODE_PROJECT = 'tsconfig.test.json';
2+
13
module.exports = {
24
exclude: '**/*.jest.spec.ts',
3-
require: 'ts-node/register',
5+
require: ['ts-node/register'],
46
timeout: '30000',
57
slow: '5000',
68
exit: true,
7-
require: 'ts-node.js',
89
'check-leaks': true,
910
};

eslint.config.mjs

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,68 @@
1-
// @ts-check
2-
31
import eslint from '@eslint/js';
4-
import tseslint from 'typescript-eslint';
5-
6-
import importPlugin from 'eslint-plugin-import';
7-
import chaiFriendly from 'eslint-plugin-chai-friendly';
8-
import mochaPlugin from 'eslint-plugin-mocha';
9-
import eslintConfigPrettier from 'eslint-config-prettier/flat';
2+
import tsPlugin from '@typescript-eslint/eslint-plugin';
3+
import tsParser from '@typescript-eslint/parser';
104

11-
export default tseslint.config(
5+
export default [
126
eslint.configs.recommended,
13-
tseslint.configs.recommended,
14-
mochaPlugin.configs.recommended,
15-
importPlugin.flatConfigs.recommended,
16-
chaiFriendly.configs.recommendedFlat,
17-
eslintConfigPrettier
18-
);
7+
{
8+
files: ['**/*.ts'],
9+
ignores: ['**/*.d.ts'],
10+
languageOptions: {
11+
parser: tsParser,
12+
globals: {
13+
// Node.js globals
14+
Buffer: 'readonly',
15+
require: 'readonly',
16+
module: 'writable',
17+
exports: 'writable',
18+
process: 'readonly',
19+
console: 'readonly',
20+
__dirname: 'readonly',
21+
__filename: 'readonly',
22+
// Test globals
23+
describe: 'readonly',
24+
context: 'readonly',
25+
it: 'readonly',
26+
before: 'readonly',
27+
after: 'readonly',
28+
beforeEach: 'readonly',
29+
afterEach: 'readonly',
30+
},
31+
},
32+
plugins: {
33+
'@typescript-eslint': tsPlugin,
34+
},
35+
rules: {
36+
'no-unused-vars': 'off',
37+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
38+
'@typescript-eslint/no-explicit-any': 'warn',
39+
'no-redeclare': 'off',
40+
},
41+
},
42+
{
43+
files: ['**/*.js'],
44+
languageOptions: {
45+
sourceType: 'commonjs',
46+
globals: {
47+
module: 'writable',
48+
exports: 'writable',
49+
require: 'readonly',
50+
Buffer: 'readonly',
51+
console: 'readonly',
52+
process: 'readonly',
53+
__dirname: 'readonly',
54+
__filename: 'readonly',
55+
describe: 'readonly',
56+
context: 'readonly',
57+
it: 'readonly',
58+
before: 'readonly',
59+
after: 'readonly',
60+
beforeEach: 'readonly',
61+
afterEach: 'readonly',
62+
},
63+
},
64+
rules: {
65+
'no-unused-vars': ['error', { varsIgnorePattern: '^(VERIFY_PROVIDER_RESPONSE|FfiFunctionResult|FfiLogLevelFilter|FnValidationStatus)$' }],
66+
},
67+
},
68+
];

src/ffi/types.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type FfiMessageHandle = number;
88
// TODO: Replace this pattern of type + const + lint disable with enums
99

1010
export type FfiSpecificationVersion = 0 | 1 | 2 | 3 | 4 | 5;
11-
11+
1212
export const FfiSpecificationVersion: Record<string, FfiSpecificationVersion> =
1313
{
1414
SPECIFICATION_VERSION_UNKNOWN: 0,
@@ -20,7 +20,7 @@ export const FfiSpecificationVersion: Record<string, FfiSpecificationVersion> =
2020
};
2121

2222
export type FfiWritePactResponse = 0 | 1 | 2 | 3;
23-
23+
2424
export const FfiWritePactResponse: Record<string, FfiWritePactResponse> = {
2525
SUCCESS: 0,
2626
GENERAL_PANIC: 1,
@@ -29,7 +29,7 @@ export const FfiWritePactResponse: Record<string, FfiWritePactResponse> = {
2929
};
3030

3131
export type FfiWriteMessagePactResponse = 0 | 1 | 2;
32-
32+
3333
export const FfiWriteMessagePactResponse: Record<
3434
string,
3535
FfiWriteMessagePactResponse
@@ -40,7 +40,7 @@ export const FfiWriteMessagePactResponse: Record<
4040
};
4141

4242
export type FfiConfigurePluginResponse = 0 | 1 | 2 | 3;
43-
43+
4444
export const FfiConfigurePluginResponse: Record<
4545
string,
4646
FfiConfigurePluginResponse
@@ -52,7 +52,7 @@ export const FfiConfigurePluginResponse: Record<
5252
};
5353

5454
export type FfiPluginInteractionResponse = 0 | 1 | 2 | 3 | 4 | 5 | 6;
55-
55+
5656
export const FfiPluginInteractionResponse: Record<
5757
string,
5858
FfiPluginInteractionResponse
@@ -87,7 +87,7 @@ export const CREATE_MOCK_SERVER_ERRORS = {
8787
-5 The address is not valid
8888
-6 Could not create the TLS configuration with the self-signed certificate
8989
*/
90-
90+
9191
export enum VERIFY_PROVIDER_RESPONSE {
9292
VERIFICATION_SUCCESSFUL = 0,
9393
VERIFICATION_FAILED,

src/index.spec.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import * as chai from 'chai';
2-
import index from './index';
3-
4-
const { expect } = chai;
1+
import { expect } from 'chai';
2+
import pact from './index';
53

64
describe('Index Spec', function() {
75
it('Typescript import should work', function() {
8-
expect(index).to.be.ok;
6+
expect(pact).to.be.ok;
97
});
108
});

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import pact from './pact';
22

3-
43
module.exports = exports = pact;
54

65
export default pact;

src/logger/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { LogLevel } from './types';
44

55
// TODO: Replace this hack with https://www.npmjs.com/package/@npmcli/package-json
66
// TODO: abstract this so it's not repeated in src/verifier/nativeVerifier.ts
7-
7+
88
const pkg = require('../../package.json');
99

1010
const logContext = `pact-core@${pkg.version}`;

src/pact.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ describe('Pact Spec', function() {
1212
originalLogLevel = pact.logLevel();
1313
});
1414

15-
after(function() { return pact.logLevel(originalLogLevel); });
15+
after(function() {
16+
return pact.logLevel(originalLogLevel);
17+
});
1618

1719
context('when setting a log level', function() {
1820
it("should be able to set log level 'trace'", function() {

src/verifier/nativeVerifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { setupVerification } from './argumentMapper';
77

88
// TODO: Replace this hack with https://www.npmjs.com/package/@npmcli/package-json
99
// TODO: abstract this so it's not repeated in src/logger.ts
10-
10+
1111
const pkg = require('../../package.json');
1212

1313
export const verify = (opts: VerifierOptions): Promise<string> => {

src/verifier/validateOptions.spec.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@ describe('Verifier argument validator', function() {
2626
});
2727

2828
context('when automatically finding pacts from a broker', function() {
29-
context('when not given --pact-urls and only --pact-broker-url', function() {
30-
it('should fail with an error because provider is missing', function() {
31-
expect(() =>
32-
validateOptions({
33-
providerBaseUrl: 'http://localhost',
34-
pactBrokerUrl: 'http://foo.com',
35-
})
36-
).to.throw(/pactBrokerUrl requires the following properties/);
37-
});
38-
});
29+
context(
30+
'when not given --pact-urls and only --pact-broker-url',
31+
function() {
32+
it('should fail with an error because provider is missing', function() {
33+
expect(() =>
34+
validateOptions({
35+
providerBaseUrl: 'http://localhost',
36+
pactBrokerUrl: 'http://foo.com',
37+
})
38+
).to.throw(/pactBrokerUrl requires the following properties/);
39+
});
40+
}
41+
);
3942

4043
context('when given valid arguments', function() {
4144
it('should return a Verifier object', function() {

test/consumer.integration.spec.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ describe('FFI integration test for the HTTP Consumer API', function() {
6363
port = pact.createMockServer(HOST);
6464
});
6565

66-
it('generates a pact with success', function() { return axios
66+
it('generates a pact with success', function() {
67+
return axios
6768
.request({
6869
baseURL: `http://${HOST}:${port}`,
6970
headers: {
@@ -100,9 +101,11 @@ describe('FFI integration test for the HTTP Consumer API', function() {
100101
})
101102
.then(() => {
102103
pact.cleanupMockServer(port);
103-
}); });
104+
});
105+
});
104106

105-
it('generates a pact with failure', function() { return axios
107+
it('generates a pact with failure', function() {
108+
return axios
106109
.request({
107110
baseURL: `http://${HOST}:${port}`,
108111
headers: {
@@ -157,7 +160,8 @@ describe('FFI integration test for the HTTP Consumer API', function() {
157160
})
158161
.then(() => {
159162
pact.cleanupMockServer(port);
160-
}); });
163+
});
164+
});
161165
});
162166

163167
// See https://github.com/pact-foundation/pact-reference/issues/171 for why we have an OS switch here
@@ -197,7 +201,8 @@ describe('FFI integration test for the HTTP Consumer API', function() {
197201
port = pact.createMockServer(HOST);
198202
});
199203

200-
it('generates a pact with success', function() { return axios
204+
it('generates a pact with success', function() {
205+
return axios
201206
.request({
202207
baseURL: `http://${HOST}:${port}`,
203208
headers: {
@@ -232,7 +237,8 @@ describe('FFI integration test for the HTTP Consumer API', function() {
232237
})
233238
.then(() => {
234239
pact.cleanupMockServer(port);
235-
}); });
240+
});
241+
});
236242
});
237243

238244
// Should only run this if the plugin is installed
@@ -348,7 +354,8 @@ describe('FFI integration test for the HTTP Consumer API', function() {
348354
port = consumerPact.createMockServer(HOST);
349355
});
350356

351-
it('generates a pact with success', function() { return axios
357+
it('generates a pact with success', function() {
358+
return axios
352359
.request({
353360
baseURL: `http://${HOST}:${port}`,
354361
headers: {
@@ -385,6 +392,7 @@ describe('FFI integration test for the HTTP Consumer API', function() {
385392
})
386393
.then(() => {
387394
pact.cleanupMockServer(port);
388-
}); });
395+
});
396+
});
389397
});
390398
});

0 commit comments

Comments
 (0)