Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: added code linting #473

Merged
merged 14 commits into from
Feb 2, 2024
Merged

ci: added code linting #473

merged 14 commits into from
Feb 2, 2024

Conversation

Gmin2
Copy link
Contributor

@Gmin2 Gmin2 commented Dec 17, 2023

Description
this pr introduces linting in the repo
Related issue(s)
fix #467

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@Gmin2 Gmin2 marked this pull request as draft December 17, 2023 08:28
@smoya
Copy link
Member

smoya commented Dec 17, 2023

@Min2who please update the title of the PR according to the semantic-release prefixes (as shown in the checks). In this case, the prefix is ci.

@Gmin2 Gmin2 changed the title added code linting ci: added code linting Dec 17, 2023
@AnimeshKumar923
Copy link
Contributor

@smoya sorry to bother but the workflow requires your approval

package.json Outdated
@@ -11,7 +11,8 @@
"prepublishOnly": "npm run build",
"bundle": "cd tools/bundler && npm i && npm run bundle",
"startNewVersion": "newVersion=$npm_config_new_version node scripts/add-new-version.js",
"lint": "echo 'No linter integrated yet'",
"lint": "eslint --max-warnings 0 --config .eslintrs .",
Copy link
Contributor

@AnimeshKumar923 AnimeshKumar923 Dec 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"lint": "eslint --max-warnings 0 --config .eslintrs .",
"lint": "eslint --max-warnings 0 --config .eslintrc .",

I think this is why the workflow failed earlier, @Min2who please fix this. The file name is not matched correctly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved with da9d4ce

This comment was marked as resolved.

package.json Outdated
@@ -11,7 +11,8 @@
"prepublishOnly": "npm run build",
"bundle": "cd tools/bundler && npm i && npm run bundle",
"startNewVersion": "newVersion=$npm_config_new_version node scripts/add-new-version.js",
"lint": "echo 'No linter integrated yet'",
"lint": "eslint --max-warnings 0 --config .eslintrc .",
"lint:fix": "eslint --max-warnings 0 --config . --fix",
Copy link
Contributor

@AnimeshKumar923 AnimeshKumar923 Dec 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"lint:fix": "eslint --max-warnings 0 --config . --fix",
"lint:fix": "eslint --max-warnings 0 --config .eslintrc . --fix",

@Min2who This should be as given here

This comment was marked as resolved.

This comment was marked as resolved.

@smoya
Copy link
Member

smoya commented Dec 18, 2023

@Min2who Can this be turned in to a final PR? Looks ok to me.

@Gmin2 Gmin2 marked this pull request as ready for review December 18, 2023 15:31
@Gmin2
Copy link
Contributor Author

Gmin2 commented Dec 18, 2023

@Min2who Can this be turned in to a final PR? Looks ok to me.

@smoya done

@smoya
Copy link
Member

smoya commented Dec 19, 2023

@smoya
Copy link
Member

smoya commented Dec 19, 2023

The tests are now failing because of linting issues 👍
Perhaps it makes sense to run a npm run lint:fix and commit the result here.

@Gmin2
Copy link
Contributor Author

Gmin2 commented Dec 19, 2023

@smoya if i dont add comment disabling the eslint error it fails npm run lint and if i do as in this case it is failing sonarcloud code analysis what should i do

@AnimeshKumar923
Copy link
Contributor

Hey @smoya @Min2who 👋
I tried doing the steps you provided in the issue and I'm also getting the same issue as the one which SonarCloud is giving.

After running npm run lint, the following output is being given 👇

> @asyncapi/[email protected] lint
> eslint --max-warnings 0 --config .eslintrc.yml .


Oops! Something went wrong! :(

ESLint: 8.56.0

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'security' -> object with constructor 'Object'
    |     property 'configs' -> object with constructor 'Object'
    |     property 'recommended' -> object with constructor 'Object'
    --- property 'plugins' closes the circle
Referenced from: /home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/.eslintrc.yml
    at JSON.stringify (<anonymous>)
    at /home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2156:45
    at Array.map (<anonymous>)
    at ConfigValidator.formatErrors (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2147:23)
    at ConfigValidator.validateConfigSchema (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2177:84)
    at ConfigArrayFactory._normalizeConfigData (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3019:19)
    at ConfigArrayFactory._loadExtendedPluginConfig (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3239:25)
    at ConfigArrayFactory._loadExtends (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3154:29)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3095:25)
    at _normalizeObjectConfigDataBody.next (<anonymous>)

@smoya currently I'm not having that much knowledge to debug this 😅 . You'd know better as you've knowledge of the codebase and how things are working internally, so would require you help here...

.eslintrc Outdated
Comment on lines 108 to 110
- "test/**"
- "*.spec.js"
- "*.test.js"

This comment was marked as resolved.

package.json Outdated
@@ -11,7 +11,8 @@
"prepublishOnly": "npm run build",
"bundle": "cd tools/bundler && npm i && npm run bundle",
"startNewVersion": "newVersion=$npm_config_new_version node scripts/add-new-version.js",
"lint": "echo 'No linter integrated yet'",
"lint": "eslint --max-warnings 0 --config .eslintrc .",
"lint:fix": "eslint --max-warnings 0 --config . --fix",

This comment was marked as resolved.

package.json Outdated
@@ -11,7 +11,8 @@
"prepublishOnly": "npm run build",
"bundle": "cd tools/bundler && npm i && npm run bundle",
"startNewVersion": "newVersion=$npm_config_new_version node scripts/add-new-version.js",
"lint": "echo 'No linter integrated yet'",
"lint": "eslint --max-warnings 0 --config .eslintrc .",
"lint:fix": "eslint --max-warnings 0 --config . --fix",

This comment was marked as resolved.

package.json Outdated
@@ -11,7 +11,8 @@
"prepublishOnly": "npm run build",
"bundle": "cd tools/bundler && npm i && npm run bundle",
"startNewVersion": "newVersion=$npm_config_new_version node scripts/add-new-version.js",
"lint": "echo 'No linter integrated yet'",
"lint": "eslint --max-warnings 0 --config .eslintrs .",

This comment was marked as resolved.

.eslintrc.yml Outdated
@@ -0,0 +1,112 @@
parser: "@typescript-eslint/parser"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Min2who is this needed here? I guess TypeScript and related technologies are not to be used in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i found the typescript parser to be best among the babel and ecma parser

Copy link
Member

@smoya smoya Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this feels unexpected. We are not using Typescript (yet) in this project, so I expect all JS files to fulfill with standard vanilla JS.

Unless there is a strong reason to use this, please remove this line.

scripts/add-new-version.js Outdated Show resolved Hide resolved
@@ -7,82 +7,77 @@ const ajvDraft04 = new AjvDraft04();
const Ajv = require('ajv');
const ajv = new Ajv();

function validation (excludedFiles){

/* eslint-disable sonarjs/cognitive-complexity */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AnimeshKumar923 As you recently created this script, would you be happy improving it by reducing the cognitive complexity Sonarcloud complains at this moment? I guess it is a matter of simplifying the script.

If so, let's create a new issue for it.

tools/bundler/index.js Outdated Show resolved Hide resolved
@Gmin2 Gmin2 requested a review from smoya January 9, 2024 15:53
@AnimeshKumar923
Copy link
Contributor

Hey @smoya @Min2who 👋 I tried doing the steps you provided in the issue and I'm also getting the same issue as the one which SonarCloud is giving.
After running npm run lint, the following output is being given 👇

> @asyncapi/[email protected] lint
> eslint --max-warnings 0 --config .eslintrc.yml .


Oops! Something went wrong! :(

ESLint: 8.56.0

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'security' -> object with constructor 'Object'
    |     property 'configs' -> object with constructor 'Object'
    |     property 'recommended' -> object with constructor 'Object'
    --- property 'plugins' closes the circle
Referenced from: /home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/.eslintrc.yml
    at JSON.stringify (<anonymous>)
    at /home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2156:45
    at Array.map (<anonymous>)
    at ConfigValidator.formatErrors (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2147:23)
    at ConfigValidator.validateConfigSchema (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2177:84)
    at ConfigArrayFactory._normalizeConfigData (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3019:19)
    at ConfigArrayFactory._loadExtendedPluginConfig (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3239:25)
    at ConfigArrayFactory._loadExtends (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3154:29)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3095:25)
    at _normalizeObjectConfigDataBody.next (<anonymous>)

@smoya currently I'm not having that much knowledge to debug this 😅 . You'd know better as you've knowledge of the codebase and how things are working internally, so would require you help here...

I can't reproduce this error. Ran this locally and worked fine.

It seems it's no longer giving the error. But a different error this time which is mentioned here in the 2nd screenshot: #473 (comment)

@Gmin2
Copy link
Contributor Author

Gmin2 commented Jan 10, 2024

Hey @smoya @Min2who 👋 I tried doing the steps you provided in the issue and I'm also getting the same issue as the one which SonarCloud is giving.
After running npm run lint, the following output is being given 👇

> @asyncapi/[email protected] lint
> eslint --max-warnings 0 --config .eslintrc.yml .


Oops! Something went wrong! :(

ESLint: 8.56.0

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'security' -> object with constructor 'Object'
    |     property 'configs' -> object with constructor 'Object'
    |     property 'recommended' -> object with constructor 'Object'
    --- property 'plugins' closes the circle
Referenced from: /home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/.eslintrc.yml
    at JSON.stringify (<anonymous>)
    at /home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2156:45
    at Array.map (<anonymous>)
    at ConfigValidator.formatErrors (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2147:23)
    at ConfigValidator.validateConfigSchema (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2177:84)
    at ConfigArrayFactory._normalizeConfigData (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3019:19)
    at ConfigArrayFactory._loadExtendedPluginConfig (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3239:25)
    at ConfigArrayFactory._loadExtends (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3154:29)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3095:25)
    at _normalizeObjectConfigDataBody.next (<anonymous>)

@smoya currently I'm not having that much knowledge to debug this 😅 . You'd know better as you've knowledge of the codebase and how things are working internally, so would require you help here...

I can't reproduce this error. Ran this locally and worked fine.

It seems it's no longer giving the error. But a different error this time which is mentioned here in the 2nd screenshot: #473 (comment)

If we use espree parser (the default eslint parser) then this error occur.But if we use babel-eslint parser this error does not occur

@smoya
Copy link
Member

smoya commented Jan 10, 2024

Hey @smoya @Min2who 👋 I tried doing the steps you provided in the issue and I'm also getting the same issue as the one which SonarCloud is giving.
After running npm run lint, the following output is being given 👇

> @asyncapi/[email protected] lint
> eslint --max-warnings 0 --config .eslintrc.yml .


Oops! Something went wrong! :(

ESLint: 8.56.0

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'security' -> object with constructor 'Object'
    |     property 'configs' -> object with constructor 'Object'
    |     property 'recommended' -> object with constructor 'Object'
    --- property 'plugins' closes the circle
Referenced from: /home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/.eslintrc.yml
    at JSON.stringify (<anonymous>)
    at /home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2156:45
    at Array.map (<anonymous>)
    at ConfigValidator.formatErrors (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2147:23)
    at ConfigValidator.validateConfigSchema (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2177:84)
    at ConfigArrayFactory._normalizeConfigData (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3019:19)
    at ConfigArrayFactory._loadExtendedPluginConfig (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3239:25)
    at ConfigArrayFactory._loadExtends (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3154:29)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/home/animeshkumar923/Desktop/open-source/asyncapi-spec-json-schemas/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3095:25)
    at _normalizeObjectConfigDataBody.next (<anonymous>)

@smoya currently I'm not having that much knowledge to debug this 😅 . You'd know better as you've knowledge of the codebase and how things are working internally, so would require you help here...

I can't reproduce this error. Ran this locally and worked fine.

It seems it's no longer giving the error. But a different error this time which is mentioned here in the 2nd screenshot: #473 (comment)

If we use espree parser (the default eslint parser) then this error occur.But if we use babel-eslint parser this error does not occur

But that error is expected. We should fix the code and not hiding it by using another eslint parser.

@AnimeshKumar923
Copy link
Contributor

But that error is expected. We should fix the code and not hiding it by using another eslint parser.

I think we should create a new issue and proceed to resolve it and then after resolution the linting would pass.

Thoughts?

- plugin:sonarjs/recommended

parserOptions:
requireConfigFile: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to make it work with async

Suggested change
requireConfigFile: false
requireConfigFile: false
ecmaVersion: 2018

@@ -42,29 +42,29 @@ function addNewSchemaVersion(newVersion, newVersionDir, latestVersion) {
const obj = require(objFile);

// Adapt all the MUST supported schema formats
let mustSupportedSchemaFormats = [] = obj?.else?.properties?.schemaFormat?.anyOf[1]?.enum;
let mustSupportedSchemaFormats = obj?.else?.properties?.schemaFormat?.anyOf[1]?.enum || [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugly, but i can't come with another solution compatible with this version of ES.

You will need to apply the same approach for the rest.

Suggested change
let mustSupportedSchemaFormats = obj?.else?.properties?.schemaFormat?.anyOf[1]?.enum || [];
let mustSupportedSchemaFormats = obj && obj.else && obj.else.properties && obj.else.properties.schemaFormat && obj.else.properties.schemaFormat.anyOf && obj.else.properties.schemaFormat.anyOf[1] && obj.else.properties.schemaFormat.anyOf[1].enum ? obj.else.properties.schemaFormat.anyOf[1].enum : [];

@smoya
Copy link
Member

smoya commented Jan 11, 2024

But that error is expected. We should fix the code and not hiding it by using another eslint parser.

I think we should create a new issue and proceed to resolve it and then after resolution the linting would pass.

Thoughts?

I don't mind if done here or outside.

I dropped a suggestion on how to fix it (ugly but 🤷 ) https://github.com/asyncapi/spec-json-schemas/pull/473/files#r1449018980

@AnimeshKumar923
Copy link
Contributor

But that error is expected. We should fix the code and not hiding it by using another eslint parser.

I think we should create a new issue and proceed to resolve it and then after resolution the linting would pass.
Thoughts?

I don't mind if done here or outside.

I dropped a suggestion on how to fix it (ugly but 🤷 ) https://github.com/asyncapi/spec-json-schemas/pull/473/files#r1449018980

If it's not that significant of a change (assuming it won't stretch out too far if we implement it), I think it would be okay do it in this PR itself. 👍

@Gmin2
Copy link
Contributor Author

Gmin2 commented Jan 12, 2024

But that error is expected. We should fix the code and not hiding it by using another eslint parser.

I think we should create a new issue and proceed to resolve it and then after resolution the linting would pass.
Thoughts?

I don't mind if done here or outside.
I dropped a suggestion on how to fix it (ugly but 🤷 ) https://github.com/asyncapi/spec-json-schemas/pull/473/files#r1449018980

If it's not that significant of a change (assuming it won't stretch out too far if we implement it), I think it would be okay do it in this PR itself. 👍

@AnimeshKumar923 doing this change in this pr only after completing #482

@AnimeshKumar923
Copy link
Contributor

AnimeshKumar923 commented Jan 31, 2024

@Min2who I think you can start working on this one now as #482 got resolved.

@Gmin2
Copy link
Contributor Author

Gmin2 commented Feb 1, 2024

@Min2who I think you can start working on this one now as #482 got resolved.

done @AnimeshKumar923 👍

Copy link

sonarqubecloud bot commented Feb 1, 2024

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

2 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Member

@smoya smoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀🌔

@smoya
Copy link
Member

smoya commented Feb 2, 2024

pinging random mantainers to review besides me @dalelane @char0n

Copy link
Collaborator

@dalelane dalelane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

The impact of the "no-unsafe-optional-chaining" rule was an interesting one to me, I hadn't come across that before, because at first glance I was going to say this makes the code less readable - but having read the docs for the lint rule, I see now why you've done this.

@smoya
Copy link
Member

smoya commented Feb 2, 2024

/rtm

@asyncapi-bot asyncapi-bot merged commit 4021e8e into asyncapi:master Feb 2, 2024
10 checks passed
@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 6.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add code linting (eslint) as part of CI script
5 participants