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

[Doc][README] trouble shooting section should use require if the examples in README are JavaScript #15746

Closed
jeremymeng opened this issue Jun 15, 2021 · 27 comments
Labels
Client This issue points to a problem in the data-plane of the library. EngSys This issue is impacting the engineering system. eslint plugin help wanted This issue is tracking work for which community contributions would be welcomed and appreciated

Comments

@jeremymeng
Copy link
Member

jeremymeng commented Jun 15, 2021

We have seen in UX Study that participants copied and pasted the code into a NodeJS javascript file but the code didn't work because it's using import which doesn't work in default NodeJS project. We should update those to use const { setLogLevel } = require("@azure/logger");

@jeremymeng jeremymeng added the Client This issue points to a problem in the data-plane of the library. label Jun 15, 2021
@ramya-rao-a
Copy link
Contributor

@deyaaeldeen Do you think we can have a linter rule for our package readmes to catch such cases?

@ramya-rao-a ramya-rao-a added eslint plugin EngSys This issue is impacting the engineering system. labels Jun 15, 2021
@ramya-rao-a ramya-rao-a added this to the Backlog milestone Jun 15, 2021
@deyaaeldeen
Copy link
Member

@ramya-rao-a if you mean just checking for import syntax, I think we can. But if we want to make sure the code snippet as a whole runs fine, this is another story.

@ramya-rao-a
Copy link
Contributor

Yes agreed. I meant to only catch the import syntax

@ramya-rao-a ramya-rao-a added the help wanted This issue is tracking work for which community contributions would be welcomed and appreciated label Jul 26, 2021
@ramya-rao-a ramya-rao-a modified the milestones: Backlog, [2021] December Jul 26, 2021
@ramya-rao-a
Copy link
Contributor

Code pointers for anyone wanting to fix this:

@jeremymeng
Copy link
Member Author

eslint might not be able to work on markdown files?

@deyaaeldeen
Copy link
Member

@jeremymeng I think something like this could work: https://github.com/eslint/eslint-plugin-markdown

@WeiJun428
Copy link
Contributor

I would like to work on this as suggested by @deyaaeldeen though I think I need some clarification. I am aware that I should change all import to require but does this only apply to logger as mentioned above? And can I get some examples in the repo for investigation? Thank you!

@deyaaeldeen
Copy link
Member

@WeiJun428 the idea is to make sure the trouble shooting section in every package's readme file uses CommonJS module syntax so that Node.JS users could run the code without issues. For example, see Text Analytics's troubleshooting section, it uses ES modules, but we would like that to be rewritten to use CommonJS syntax (require) instead.

@deyaaeldeen
Copy link
Member

@jeremymeng I think it makes sense to be consistent about the module syntax across the whole readme file, do you think there're any downsides for using CommonJS throughout? /cc @xirzec @witemple-msft

@jeremymeng
Copy link
Member Author

do you think there're any downsides for using CommonJS throughout

I prefer CommonJS too. Ideally customers should be able to copy and paste code snippets without running into problems.

@xirzec
Copy link
Member

xirzec commented Dec 2, 2021

I agree that we should switch to CommonJS for code snippets (at least until NodeJS more wholeheartedly embraces import syntax)

@deyaaeldeen
Copy link
Member

@jeremymeng @xirzec thanks!

@WeiJun428 ok let's generalize this issue to be about ensuring using require syntax in all code snippets for any imported package.

@WeiJun428
Copy link
Contributor

WeiJun428 commented Jan 23, 2022

Hi, I would like to get some clarification on where to incorporate eslint-plugin-markdown plugin into the repo. Specifically, I am wondering whether should I put my config in .eslintrc.json or azure-sdk-base.ts in eslint-plugin-azure-sdk, or both? (I noticed they works on very different environment but what are their main differences?)

@deyaaeldeen
Copy link
Member

@WeiJun428 thanks for following up! azure-sdk-base.ts is the place for configuring 3rd party plugins so I believe this is what you're looking for. On the other hand, .eslintrc.json is used to lint the source code for the plugin itself only.

@WeiJun428
Copy link
Contributor

Thanks @deyaaeldeen for your answer! Now, I am trying to use no-restricted-import to ban any import statement in md file. But I noticed that I should probably modify the existing scripts in each package.json, specifically:

    "lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]",
    "lint": "eslint package.json api-extractor.json src test --ext .ts",
    // Probably need to add *.md to target files and --ext .md to lint md files at root of each sdk

so that rush lint and rushx lint will work as expected. Am I understanding it correctly? If so, how should I do that?

@deyaaeldeen
Copy link
Member

@WeiJun428 You're right that current npm linting scripts ignore the README.md files so they will have to be updated. Instead of adding all .md files, let's add README.md only to the linting commands:

 "lint:fix": "eslint package.json README.md api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]",
 "lint": "eslint package.json README.md api-extractor.json src test --ext .ts",

jeremymeng pushed a commit that referenced this issue Mar 2, 2022
…ript code blocks (#20408)

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.
@jeremymeng
Copy link
Member Author

@WeiJun428 I created a feature branch feature/enable-linting-readme. You can create PR targeting that branch for the rest of packages so we can avoid triggering massive CI validations.

@WeiJun428
Copy link
Contributor

@jeremymeng I didn't see the feature branch feature/enable-linting-readme on my end. I wonder where am I supposed to find it?

@jeremymeng
Copy link
Member Author

@WeiJun428 This could be a permission issue. I will try to find a solution, meanwhile you can work on your own branch.

@jeremymeng
Copy link
Member Author

@WeiJun428
Copy link
Contributor

WeiJun428 commented Mar 11, 2022

@jeremymeng I wonder if there is a good way to track the progress of enable linting readme in all sdk? Something like a list or checkbox of all to-be-fixed sdk? Should we enable it in tools such as eslint-plugin-azure-sdk and dev-tool as well?

@jeremymeng
Copy link
Member Author

@WeiJun428 good question! We don't have inventory of non-generated SDK libraries. Let me double check to see if I can find anything helpful. The main goal of this work is helping SDK customers who copy and paste code. It doesn't really apply to internal tools so we don't need to enable this rule for them.

@jeremymeng jeremymeng added the Impact++ This pull request was submitted by a member of the Impact++ team. label Mar 11, 2022
@jeremymeng
Copy link
Member Author

@weiThe list below should be pretty close

  • @azure/ai-anomaly-detector - sdk/anomalydetector/ai-anomaly-detector
  • @azure/app-configuration - sdk/appconfiguration/app-configuration
  • @azure/attestation - sdk/attestation/attestation
  • @azure/communication-chat - sdk/communication/communication-chat
  • @azure/communication-common - sdk/communication/communication-common
  • @azure/communication-identity - sdk/communication/communication-identity
  • @azure/communication-network-traversal - sdk/communication/communication-network-traversal
  • @azure/communication-phone-numbers - sdk/communication/communication-phone-numbers
  • @azure-tools/communication-short-codes - sdk/communication/communication-short-codes
  • @azure/communication-sms - sdk/communication/communication-sms
  • @azure/container-registry - sdk/containerregistry/container-registry
  • @azure/cosmos - sdk/cosmosdb/cosmos
  • @azure/iot-device-update - sdk/deviceupdate/iot-device-update
  • @azure/digital-twins-core - sdk/digitaltwins/digital-twins-core
  • @azure/dtdl-parser - sdk/digitaltwins/dtdl-parser
  • @azure/eventgrid - sdk/eventgrid/eventgrid
  • @azure/event-hubs - sdk/eventhub/event-hubs
  • @azure/eventhubs-checkpointstore-blob - sdk/eventhub/eventhubs-checkpointstore-blob
  • @azure/eventhubs-checkpointstore-table - sdk/eventhub/eventhubs-checkpointstore-table
  • @azure/ai-form-recognizer - sdk/formrecognizer/ai-form-recognizer
  • @azure/identity - sdk/identity/identity
  • @azure/identity-cache-persistence - sdk/identity/identity-cache-persistence
  • @azure/identity-vscode - sdk/identity/identity-vscode
  • @azure/opentelemetry-instrumentation-azure-sdk - sdk/instrumentation/opentelemetry-instrumentation-azure-sdk
  • @azure/iot-modelsrepository - sdk/iot/iot-modelsrepository
  • @azure/keyvault-admin - sdk/keyvault/keyvault-admin
  • @azure/keyvault-certificates - sdk/keyvault/keyvault-certificates
  • @azure/keyvault-keys - sdk/keyvault/keyvault-keys
  • @azure/keyvault-secrets - sdk/keyvault/keyvault-secrets
  • @azure/ai-metrics-advisor - sdk/metricsadvisor/ai-metrics-advisor
  • @azure/mixed-reality-authentication - sdk/mixedreality/mixed-reality-authentication
  • @azure/monitor-opentelemetry-exporter - sdk/monitor/monitor-opentelemetry-exporter
  • @azure/monitor-query - sdk/monitor/monitor-query
  • @azure/quantum-jobs - sdk/quantum/quantum-jobs
  • @azure/mixed-reality-remote-rendering - sdk/remoterendering/mixed-reality-remote-rendering
  • @azure/schema-registry - sdk/schemaregistry/schema-registry
  • @azure/schema-registry-avro - sdk/schemaregistry/schema-registry-avro
  • @azure/search-documents - sdk/search/search-documents
  • @azure/service-bus - sdk/servicebus/service-bus
  • @azure/storage-blob - sdk/storage/storage-blob
  • @azure/storage-blob-changefeed - sdk/storage/storage-blob-changefeed
  • @azure/storage-file-datalake - sdk/storage/storage-file-datalake
  • @azure/storage-file-share - sdk/storage/storage-file-share
  • @azure/storage-queue - sdk/storage/storage-queue
  • @azure/synapse-access-control - sdk/synapse/synapse-access-control
  • @azure/synapse-artifacts - sdk/synapse/synapse-artifacts
  • @azure/synapse-managed-private-endpoints - sdk/synapse/synapse-managed-private-endpoints
  • @azure/synapse-monitoring - sdk/synapse/synapse-monitoring
  • @azure/synapse-spark - sdk/synapse/synapse-spark
  • @azure/data-tables - sdk/tables/data-tables
  • @azure/template - sdk/template/template
  • @azure/ai-text-analytics - sdk/textanalytics/ai-text-analytics
  • @azure/video-analyzer-edge - sdk/videoanalyzer/video-analyzer-edge
  • @azure/web-pubsub - sdk/web-pubsub/web-pubsub
  • @azure/web-pubsub-express - sdk/web-pubsub/web-pubsub-express

@WeiJun428
Copy link
Contributor

WeiJun428 commented Mar 17, 2022

Thanks! @jeremymeng. I have tried to create a PR targeting that branch but I noticed that it also includes 12 other commits perhaps due to difference between the versions of repo that I fetch and the feature branch itself. Would that be an issue?

@jeremymeng
Copy link
Member Author

@WeiJun428 Let me see if I can update the feature branch to also include those changes.

@jeremymeng jeremymeng removed the Impact++ This pull request was submitted by a member of the Impact++ team. label Jan 18, 2023
@topshot99
Copy link
Member

@jeremymeng is this issue resolved? If so, can we close it?

Copy link

Hi @jeremymeng, we deeply appreciate your input into this project. Regrettably, this issue has remained inactive for over 2 years, leading us to the decision to close it. We've implemented this policy to maintain the relevance of our issue queue and facilitate easier navigation for new contributors. If you still believe this topic requires attention, please feel free to create a new issue, referencing this one. Thank you for your understanding and ongoing support.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 15, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 15, 2024
@xirzec xirzec removed this from the Backlog milestone May 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. EngSys This issue is impacting the engineering system. eslint plugin help wanted This issue is tracking work for which community contributions would be welcomed and appreciated
Projects
None yet
Development

No branches or pull requests

6 participants