Skip to content

chore: lint .js and .mjs files (in addition to the existing .ts file linting) #2940

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

trentm
Copy link
Contributor

@trentm trentm commented Jul 16, 2025

In #2567 support
was added to eslint.config.js for linting .js and .mjs files -- before it
only supported .ts files.
Originally this was added to support linting examples/... which includes many
.js files.

This change enables linting of .js and .mjs files in the rest of the repo.

Refs: #2891

…linting)

In open-telemetry#2567 support
was added to eslint.config.js for linting .js and .mjs files -- before it
only supported .ts files.
Originally this was added to support linting examples/... which includes many
.js files.

This change enables linting of .js and .mjs files in the rest of the repo.

Refs: open-telemetry#2891
@trentm
Copy link
Contributor Author

trentm commented Jul 16, 2025

^^ the first commit is just the package.json changes. Subsequent commits will include lint:fix changes (and if necessary manual changes to for npm run lint to pass).

@trentm trentm added the has:sponsor This package or feature has a sponsor that has volunteered to review PRs and respond to questions label Jul 16, 2025
@trentm
Copy link
Contributor Author

trentm commented Jul 16, 2025

After running lint:fix (where 99% of changes were style-only tweaks to .eslintrc.js files), the only lint failures are in instr-aws-lambda:

      /Users/trentm/tm/opentelemetry-js-contrib2/packages/instrumentation-aws-lambda/test/lambda-test/async.js
        18:35  error  'event' is defined but never used    no-unused-vars
        18:42  error  'context' is defined but never used  no-unused-vars
        22:33  error  'event' is defined but never used    no-unused-vars
        22:40  error  'context' is defined but never used  no-unused-vars
        26:39  error  'event' is defined but never used    no-unused-vars
        26:46  error  'context' is defined but never used  no-unused-vars
        30:35  error  'event' is defined but never used    no-unused-vars
        30:42  error  'context' is defined but never used  no-unused-vars
        34:50  error  'event' is defined but never used    no-unused-vars
        34:57  error  'context' is defined but never used  no-unused-vars

      /Users/trentm/tm/opentelemetry-js-contrib2/packages/instrumentation-aws-lambda/test/lambda-test/sync.js
        22:27  error  'event' is defined but never used     no-unused-vars
        22:34  error  'context' is defined but never used   no-unused-vars
        22:43  error  'callback' is defined but never used  no-unused-vars
        30:33  error  'event' is defined but never used     no-unused-vars
        30:40  error  'context' is defined but never used   no-unused-vars
        30:49  error  'callback' is defined but never used  no-unused-vars

      ✖ 27 problems (16 errors, 11 warnings)

All are with the no-unused-vars rule.

Note that our eslint rules for TypeScript test files turn this rule off:

"@typescript-eslint/no-unused-vars": "off",

We could do the same for .js files (Option 1), or add a more nuanced config something like this, which supports adding a leading _ to a var name to have it skip the "no-unused-vars" rule (Option 2):

        "no-unused-vars": [
            "error",
            {
                "vars": "all",
                "args": "all",
                "caughtErrors": "all",
                "argsIgnorePattern": "^_",
                "caughtErrorsIgnorePattern": "^_",
                "varsIgnorePattern": "^_"
            }
        ]

Anyone have opinions?

Update: In commit 092f156 I've done "Option 1".

Copy link

codecov bot commented Jul 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.05%. Comparing base (74ddb1e) to head (092f156).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2940      +/-   ##
==========================================
- Coverage   89.07%   89.05%   -0.02%     
==========================================
  Files         188      188              
  Lines        9223     9223              
  Branches     1900     1900              
==========================================
- Hits         8215     8214       -1     
- Misses       1008     1009       +1     

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has:sponsor This package or feature has a sponsor that has volunteered to review PRs and respond to questions pkg:auto-configuration-propagators pkg:auto-instrumentations-node pkg:auto-instrumentations-web pkg:host-metrics pkg:id-generator-aws-xray pkg:instrumentation-amqplib pkg:instrumentation-aws-lambda pkg:instrumentation-aws-sdk pkg:instrumentation-bunyan pkg:instrumentation-cassandra-driver pkg:instrumentation-connect pkg:instrumentation-cucumber pkg:instrumentation-dataloader pkg:instrumentation-dns pkg:instrumentation-document-load pkg:instrumentation-express pkg:instrumentation-fastify pkg:instrumentation-fs pkg:instrumentation-generic-pool pkg:instrumentation-graphql pkg:instrumentation-hapi pkg:instrumentation-ioredis pkg:instrumentation-kafkajs pkg:instrumentation-knex pkg:instrumentation-koa pkg:instrumentation-long-task pkg:instrumentation-lru-memoizer pkg:instrumentation-memcached pkg:instrumentation-mongodb pkg:instrumentation-mongoose pkg:instrumentation-mysql pkg:instrumentation-mysql2 pkg:instrumentation-nestjs-core pkg:instrumentation-net pkg:instrumentation-oracledb pkg:instrumentation-pg pkg:instrumentation-pino pkg:instrumentation-redis pkg:instrumentation-restify pkg:instrumentation-router pkg:instrumentation-runtime-node pkg:instrumentation-socket.io pkg:instrumentation-tedious pkg:instrumentation-undici pkg:instrumentation-user-interaction pkg:instrumentation-winston pkg:plugin-react-load pkg:propagation-utils pkg:propagator-aws-xray pkg:propagator-aws-xray-lambda pkg:propagator-instana pkg:propagator-ot-trace pkg:redis-common pkg:resource-detector-alibaba-cloud pkg:resource-detector-aws pkg:resource-detector-azure pkg:resource-detector-container pkg:resource-detector-gcp pkg:resource-detector-github pkg:resource-detector-instana pkg:sampler-aws-xray pkg:sql-common pkg:test-utils pkg-status:unmaintained This package is unmaintained. Only bugfixes may be acceped until a new owner has been found.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants