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

Enable a linter rule to prevent usage of "import" in README.md javascript code blocks #20408

Merged
merged 8 commits into from
Mar 2, 2022

Conversation

WeiJun428
Copy link
Contributor

@WeiJun428 WeiJun428 commented Feb 16, 2022

This is a PR that is intended to solve issue #15746.

Summary of What I did:

  • ran rush add -p eslint-plugin-markdown --dev in common\tools\eslint-plugin-azure-sdk
  • modified common\tools\eslint-plugin-azure-sdk\src\configs\azure-sdk-base.ts:
    • included the eslint-plugin-markdown plugin,
    • added override configuration that splits typescript and javascript linting.
    • used no-restricted-import to inhibit ES6 import usage.
  • added README.md as target and removed --ext option of lint script in sdk\textanalytics\ai-text-analytics\package.json and fixed the existing error.

@ghost ghost added Cognitive - Text Analytics eslint plugin customer-reported Issues that are reported by GitHub users external to the Azure organization. labels Feb 16, 2022
@ghost
Copy link

ghost commented Feb 16, 2022

Thank you for your contribution WeiJun428! We will review the pull request and get back to you soon.

@ghost ghost added the Impact++ This pull request was submitted by a member of the Impact++ team. label Feb 16, 2022
@jeremymeng
Copy link
Member

I tried npx eslint README.md --debug and found that we are using javascript tag for the code block.

eslint:linter A code block was found: '17.javascript' +0ms

so we probably need to support both *.js and *.javascript in the overrides config.

There's also another issue. Looks that we need to change eslint to allow parsing .javascript extension.

The file does not match your project config: README.md/20_20.javascript.
The extension for the file (.javascript) is non-standard. It should be added to your existing "parserOptions.extraFileExtensions"

@WeiJun428
Copy link
Contributor Author

WeiJun428 commented Feb 20, 2022

Thank you, @jeremymeng!

In my recent commits, I:

  • enabled javascript extension in parserOptions/extraFileExtension
  • supported javascript in overrides config by using "**/*.md/*.{js,javascript}"
  • factored out typescript specific parserOptions/project, extends, and rules in override to avoid applying type-specific rules to JavaScript code, according to "StackOverflow: parserOptions.project" has been set for @typescript-eslint/parser
  • added a custom error message to no-restricted-import: "Please use require instead of import."
  • changed --ext .ts to --ext .ts,.md,.javascript,.js in lint scripts in sdk\textanalytics\ai-text-analytics\package.json to enable markdown file linting

The only thing left to enable the rule in every sdk is adding README.md and --ext .ts,.md,.javascript,.js to lint: and lint:fix in package.json of every sdk root repo. (probably will not be done in this PR)

@WeiJun428 WeiJun428 marked this pull request as ready for review February 20, 2022 23:54
@WeiJun428
Copy link
Contributor Author

@jeremymeng, I have fixed the errors and resolved the conflicts in my recent commits.

Copy link
Member

@jeremymeng jeremymeng left a comment

Choose a reason for hiding this comment

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

The split in azure-sdk-base makes sense to me since we don't want to to use ts rules on javascript.

@deyaaeldeen @witemple-msft could you please review too?

@jeremymeng
Copy link
Member

@WeiJun428 please update PR description as some comments are outdated now. Thanks!

Copy link
Member

@deyaaeldeen deyaaeldeen left a comment

Choose a reason for hiding this comment

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

It looks good other than the issues highlighted in existing comments. Thanks for your contribution!

@check-enforcer
Copy link

check-enforcer bot commented Mar 2, 2022

This pull request is protected by Check Enforcer.

What is Check Enforcer?

Check Enforcer helps ensure all pull requests are covered by at least one check-run (typically an Azure Pipeline). When all check-runs associated with this pull request pass then Check Enforcer itself will pass.

Why am I getting this message?

You are getting this message because Check Enforcer did not detect any check-runs being associated with this pull request within five minutes. This may indicate that your pull request is not covered by any pipelines and so Check Enforcer is correctly blocking the pull request being merged.

What should I do now?

If the check-enforcer check-run is not passing and all other check-runs associated with this PR are passing (excluding license-cla) then you could try telling Check Enforcer to evaluate your pull request again. You can do this by adding a comment to this pull request as follows:
/check-enforcer evaluate
Typically evaulation only takes a few seconds. If you know that your pull request is not covered by a pipeline and this is expected you can override Check Enforcer using the following command:
/check-enforcer override
Note that using the override command triggers alerts so that follow-up investigations can occur (PRs still need to be approved as normal).

What if I am onboarding a new service?

Often, new services do not have validation pipelines associated with them, in order to bootstrap pipelines for a new service, you can issue the following command as a pull request comment:
/azp run prepare-pipelines
This will run a pipeline that analyzes the source tree and creates the pipelines necessary to build and validate your pull request. Once the pipeline has been created you can trigger the pipeline using the following comment:
/azp run js - [service] - ci

@WeiJun428
Copy link
Contributor Author

/check-enforcer override

@jeremymeng
Copy link
Member

Looking good now! @WeiJun428 please update PR title and description.

@WeiJun428 WeiJun428 changed the title Issue 15746 draft Issue-15746 Mar 2, 2022
@WeiJun428
Copy link
Contributor Author

@jeremymeng updated!

@witemple-msft
Copy link
Member

The code and changes to the linter configuration look good. Could you give this issue a descriptive title? Something like "[eslint-plugin] Support linting README.md and checking for require instead of import"?

@jeremymeng jeremymeng changed the title Issue-15746 Enable a linter rule to prevent usage of "import" in README.md javascript code blocks Mar 2, 2022
@jeremymeng jeremymeng merged commit b08752e into Azure:main Mar 2, 2022
@jeremymeng
Copy link
Member

The code and changes to the linter configuration look good. Could you give this issue a descriptive title? Something like "[eslint-plugin] Support linting README.md and checking for require instead of import"?

Oops sorry @witemple-msft I didn't see your comments when I tweaked the title then merged this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cognitive - Text Analytics customer-reported Issues that are reported by GitHub users external to the Azure organization. eslint plugin Impact++ This pull request was submitted by a member of the Impact++ team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants