Skip to content

Commit 534f752

Browse files
committed
wip: fix lints
1 parent 6e14182 commit 534f752

18 files changed

+369
-248
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/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function getPlatformArchSpecificPackage() {
4343
resolvedPackagePath = resolvedPackagePath.replace('/package.json', '');
4444
}
4545
return resolvedPackagePath;
46-
} catch (e) {
46+
} catch {
4747
throw new Error(
4848
`Couldn't find npm package ${platformArchSpecificPackage} \n 💡 you can tell Pact where the npm package is located with env var $PACT_PREBUILD_PACKAGE_LOCATION`
4949
);
@@ -151,7 +151,7 @@ const initialiseFfi = (): typeof ffi => {
151151
return false;
152152
}
153153
return true;
154-
} catch (error) {
154+
} catch {
155155
return true;
156156
}
157157
});

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: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import * as chai from 'chai';
2-
import index from './index';
1+
import { expect } from 'chai';
2+
import pact from './index';
33

4-
const { expect } = chai;
5-
6-
describe('Index Spec', function() {
7-
it('Typescript import should work', function() {
8-
expect(index).to.be.ok;
4+
describe('Index Spec', function () {
5+
it('Typescript import should work', function () {
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: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,40 @@ import pact from './pact';
44

55
chai.use(chaiAsPromised);
66

7-
describe('Pact Spec', function() {
8-
describe('Set Log Level', function() {
7+
describe('Pact Spec', function () {
8+
describe('Set Log Level', function () {
99
let originalLogLevel: any;
1010
// Reset log level after the tests
11-
before(function() {
11+
before(function () {
1212
originalLogLevel = pact.logLevel();
1313
});
1414

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

17-
context('when setting a log level', function() {
18-
it("should be able to set log level 'trace'", function() {
19+
context('when setting a log level', function () {
20+
it("should be able to set log level 'trace'", function () {
1921
pact.logLevel('trace');
2022
pact.logLevel();
2123
});
2224

23-
it("should be able to set log level 'debug'", function() {
25+
it("should be able to set log level 'debug'", function () {
2426
pact.logLevel('debug');
2527
pact.logLevel();
2628
});
2729

28-
it("should be able to set log level 'info'", function() {
30+
it("should be able to set log level 'info'", function () {
2931
pact.logLevel('info');
3032
pact.logLevel();
3133
});
3234

33-
it("should be able to set log level 'warn'", function() {
35+
it("should be able to set log level 'warn'", function () {
3436
pact.logLevel('warn');
3537
pact.logLevel();
3638
});
3739

38-
it("should be able to set log level 'error'", function() {
40+
it("should be able to set log level 'error'", function () {
3941
pact.logLevel('error');
4042
pact.logLevel();
4143
});

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> => {

0 commit comments

Comments
 (0)