Skip to content

Commit

Permalink
Use ESLint flat configuration files
Browse files Browse the repository at this point in the history
ESLint has deprecated the legacy configuration files format and adopted
a newer flat file format.

Signed-off-by: Mark S. Lewis <Mark.S.Lewis@outlook.com>
  • Loading branch information
bestbeforetoday committed May 19, 2024
1 parent b1408ec commit cbdfc43
Show file tree
Hide file tree
Showing 25 changed files with 294 additions and 208 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
overrides:
- files: "*.{js,ts}"
- files: "*.{mj,cj,j,t}s"
options:
singleQuote: true
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,11 @@ vendor-chaincode:

.PHONY: scenario-test-go
scenario-test-go: vendor-chaincode fabric-ca-client setup-softhsm
go install github.com/cucumber/godog/cmd/godog@v0.12
cd '$(scenario_dir)/go' && \
go test -timeout 20m -tags pkcs11 -v -args '$(scenario_dir)/features/'

.PHONY: scenario-test-go-no-hsm
scenario-test-go-no-hsm: vendor-chaincode
go install github.com/cucumber/godog/cmd/godog@v0.12
cd '$(scenario_dir)/go' && \
go test -timeout 20m -tags pkcs11 -v --godog.tags='~@hsm' -args '$(scenario_dir)/features/'

Expand Down
26 changes: 0 additions & 26 deletions node/.eslintrc.base.js

This file was deleted.

12 changes: 0 additions & 12 deletions node/.eslintrc.js

This file was deleted.

23 changes: 23 additions & 0 deletions node/eslint.config.base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import js from '@eslint/js';
import prettier from 'eslint-config-prettier';
import tseslint from 'typescript-eslint';

export default tseslint.config(js.configs.recommended, ...tseslint.configs.strictTypeChecked, prettier, {
languageOptions: {
ecmaVersion: 2023,
sourceType: 'module',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
complexity: ['error', 10],
'@typescript-eslint/explicit-function-return-type': [
'error',
{
allowExpressions: true,
},
],
},
});
12 changes: 12 additions & 0 deletions node/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import jest from 'eslint-plugin-jest';
import tseslint from 'typescript-eslint';
import base from './eslint.config.base.mjs';
import { FlatCompat } from '@eslint/eslintrc';

const compat = new FlatCompat({ baseDirectory: import.meta.dirname });

export default tseslint.config(...base, jest.configs['flat/recommended'], ...compat.plugins('eslint-plugin-tsdoc'), {
rules: {
'tsdoc/syntax': ['error'],
},
});
11 changes: 6 additions & 5 deletions node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"format": "prettier '**/*.{ts,js}' --check",
"format:fix": "prettier '**/*.{ts,js}' --write",
"generate-apidoc": "typedoc",
"lint": "eslint .",
"lint": "eslint src",
"sbom": "cyclonedx-npm --omit dev --output-format JSON --output-file sbom.json",
"test": "npm-run-all lint format unit-test",
"unit-test": "jest"
Expand All @@ -42,13 +42,13 @@
"pkcs11js": "^2.1.0"
},
"devDependencies": {
"@cyclonedx/cyclonedx-npm": "^1.16.2",
"@cyclonedx/cyclonedx-npm": "^1.18.0",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.3.0",
"@tsconfig/node18": "^18.2.4",
"@types/google-protobuf": "^3.15.12",
"@types/jest": "^29.5.12",
"@types/node": "^18.19.31",
"@typescript-eslint/eslint-plugin": "~7.6.0",
"@typescript-eslint/parser": "~7.6.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^28.2.0",
Expand All @@ -58,6 +58,7 @@
"prettier": "^3.2.5",
"ts-jest": "^29.1.2",
"typedoc": "^0.25.13",
"typescript": "~5.4.5"
"typescript": "~5.4.5",
"typescript-eslint": "^7.9.0"
}
}
52 changes: 22 additions & 30 deletions node/src/blockevents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('Block Events', () => {
newEventsRequest(
options?: BlockEventsOptions,
): BlockEventsRequest | FilteredBlockEventsRequest | BlockAndPrivateDataEventsRequest;
getCallOptions(): CallOptions[];
getCallOption(): CallOptions;
newBlockResponse(blockNumber: number): peer.DeliverResponse;
getBlockFromResponse(
response: peer.DeliverResponse,
Expand All @@ -137,8 +137,8 @@ describe('Block Events', () => {
newEventsRequest(options?) {
return network.newBlockEventsRequest(options);
},
getCallOptions() {
return client.getBlockEventsOptions();
getCallOption() {
return client.getBlockEventsOption();
},
newBlockResponse(blockNumber) {
const header = new common.BlockHeader();
Expand Down Expand Up @@ -169,8 +169,8 @@ describe('Block Events', () => {
newEventsRequest(options?) {
return network.newFilteredBlockEventsRequest(options);
},
getCallOptions() {
return client.getFilteredBlockEventsOptions();
getCallOption() {
return client.getFilteredBlockEventsOption();
},
newBlockResponse(blockNumber) {
const block = new peer.FilteredBlock();
Expand Down Expand Up @@ -198,8 +198,8 @@ describe('Block Events', () => {
newEventsRequest(options?) {
return network.newBlockAndPrivateDataEventsRequest(options);
},
getCallOptions() {
return client.getBlockAndPrivateDataEventsOptions();
getCallOption() {
return client.getBlockAndPrivateDataEventsOption();
},
newBlockResponse(blockNumber) {
const header = new common.BlockHeader();
Expand Down Expand Up @@ -227,15 +227,14 @@ describe('Block Events', () => {
Object.entries(testCases).forEach(([testName, testCase]) => {
// eslint-disable-next-line jest/valid-title
describe(testName, () => {
// eslint-disable-next-line jest/expect-expect
it('sends valid request with default start position', async () => {
const stream = newDuplexStreamResponse<common.Envelope, peer.DeliverResponse>([]);
testCase.mockResponse(stream);

await testCase.getEvents();

expect(stream.write.mock.calls.length).toBe(1);
const request = stream.write.mock.calls[0][0];

const request = stream.getRequest();
const payload = common.Payload.deserializeBinary(request.getPayload_asU8());
assertValidBlockEventsRequestHeader(payload);

Expand All @@ -250,16 +249,15 @@ describe('Block Events', () => {
await expect(network.getBlockEvents({ startBlock })).rejects.toThrow();
});

// eslint-disable-next-line jest/expect-expect
it('sends valid request with specified start block number', async () => {
const startBlock = BigInt(418);
const stream = newDuplexStreamResponse<common.Envelope, peer.DeliverResponse>([]);
testCase.mockResponse(stream);

await testCase.getEvents({ startBlock });

expect(stream.write.mock.calls.length).toBe(1);
const request = stream.write.mock.calls[0][0];

const request = stream.getRequest();
const payload = common.Payload.deserializeBinary(request.getPayload_asU8());
assertValidBlockEventsRequestHeader(payload);

Expand All @@ -269,15 +267,14 @@ describe('Block Events', () => {
assertStopPosition(seekInfo);
});

// eslint-disable-next-line jest/expect-expect
it('Uses specified start block instead of unset checkpoint', async () => {
const stream = newDuplexStreamResponse<common.Envelope, peer.DeliverResponse>([]);
testCase.mockResponse(stream);
const startBlock = BigInt(418);
await testCase.getEvents({ startBlock: startBlock, checkpoint: checkpointers.inMemory() });

expect(stream.write.mock.calls.length).toBe(1);
const request = stream.write.mock.calls[0][0];

const request = stream.getRequest();
const payload = common.Payload.deserializeBinary(request.getPayload_asU8());
assertValidBlockEventsRequestHeader(payload);

Expand All @@ -287,6 +284,7 @@ describe('Block Events', () => {
assertStopPosition(seekInfo);
});

// eslint-disable-next-line jest/expect-expect
it('Uses checkpoint block instead of specified start block', async () => {
const stream = newDuplexStreamResponse<common.Envelope, peer.DeliverResponse>([]);
testCase.mockResponse(stream);
Expand All @@ -296,9 +294,7 @@ describe('Block Events', () => {
await checkpointer.checkpointBlock(1n);
await testCase.getEvents({ startBlock: startBlock, checkpoint: checkpointer });

expect(stream.write.mock.calls.length).toBe(1);
const request = stream.write.mock.calls[0][0];

const request = stream.getRequest();
const payload = common.Payload.deserializeBinary(request.getPayload_asU8());
assertValidBlockEventsRequestHeader(payload);

Expand All @@ -308,6 +304,7 @@ describe('Block Events', () => {
assertStopPosition(seekInfo);
});

// eslint-disable-next-line jest/expect-expect
it('Uses checkpoint block zero with set transaction ID instead of specified start block', async () => {
const stream = newDuplexStreamResponse<common.Envelope, peer.DeliverResponse>([]);
testCase.mockResponse(stream);
Expand All @@ -318,9 +315,7 @@ describe('Block Events', () => {
await checkpointer.checkpointTransaction(blockNumber, 'transactionID');
await testCase.getEvents({ startBlock: startBlock, checkpoint: checkpointer });

expect(stream.write.mock.calls.length).toBe(1);
const request = stream.write.mock.calls[0][0];

const request = stream.getRequest();
const payload = common.Payload.deserializeBinary(request.getPayload_asU8());
assertValidBlockEventsRequestHeader(payload);

Expand All @@ -330,15 +325,14 @@ describe('Block Events', () => {
assertStopPosition(seekInfo);
});

// eslint-disable-next-line jest/expect-expect
it('Uses default start block instead of unset checkpoint and no start block', async () => {
const stream = newDuplexStreamResponse<common.Envelope, peer.DeliverResponse>([]);
testCase.mockResponse(stream);
const checkpointer = checkpointers.inMemory();
await testCase.getEvents({ checkpoint: checkpointer });

expect(stream.write.mock.calls.length).toBe(1);
const request = stream.write.mock.calls[0][0];

const request = stream.getRequest();
const payload = common.Payload.deserializeBinary(request.getPayload_asU8());
assertValidBlockEventsRequestHeader(payload);

Expand All @@ -353,14 +347,14 @@ describe('Block Events', () => {

await testCase.newEventsRequest().getEvents({ deadline });

const actual = testCase.getCallOptions()[0];
const actual = testCase.getCallOption();
expect(actual.deadline).toBe(deadline);
});

it('uses default call options', async () => {
await testCase.getEvents();

const actual = testCase.getCallOptions()[0];
const actual = testCase.getCallOption();
expect(actual.deadline).toBe(defaultOptions().deadline);
});

Expand Down Expand Up @@ -468,9 +462,7 @@ describe('Block Events', () => {

await testCase.getEvents();

expect(stream.write.mock.calls.length).toBe(1);
const request = stream.write.mock.calls[0][0];

const request = stream.getRequest();
const payload = common.Payload.deserializeBinary(request.getPayload_asU8());
const header = assertDefined(payload.getHeader(), 'header');
const channelHeader = common.ChannelHeader.deserializeBinary(header.getChannelHeader_asU8());
Expand Down
Loading

0 comments on commit cbdfc43

Please sign in to comment.