Closed jeremymeng closed 7 months ago
@deyaaeldeen Do you think we can have a linter rule for our package readmes to catch such cases?
@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.
Yes agreed. I meant to only catch the import syntax
Code pointers for anyone wanting to fix this:
eslint might not be able to work on markdown files?
@jeremymeng I think something like this could work: https://github.com/eslint/eslint-plugin-markdown
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!
@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.
@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
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.
I agree that we should switch to CommonJS for code snippets (at least until NodeJS more wholeheartedly embraces import syntax)
@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.
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?)
@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.
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?
@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",
@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.
@jeremymeng I didn't see the feature branch feature/enable-linting-readme
on my end. I wonder where am I supposed to find it?
@WeiJun428 This could be a permission issue. I will try to find a solution, meanwhile you can work on your own branch.
@WeiJun428 It should be available now at https://github.com/Azure/azure-sdk-for-js/tree/feature/enable-linting-readme
@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?
@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.
@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-expressThanks! @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?
@WeiJun428 Let me see if I can update the feature branch to also include those changes.
@jeremymeng is this issue resolved? If so, can we close it?
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.
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 useconst { setLogLevel } = require("@azure/logger");