3.0.2 • Published 3 months ago

eslint-cjs-to-esm v3.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

eslint-cjs-to-esm

ESLint wrapper for migration from CJS to ESM.

This tool's main use-case is to migrate from CommonJS (JavaScript/TypeScript) to ES Modules (JavaScript/TypeScript).

This tool is a wrapper of ESLint, and it built-in some rules for migration. So, you can just use this tool without any configuration.

Install

Install with npm:

npm install eslint-cjs-to-esm

Usage

Command Line Arguments are the same as those of ESLint.

npx eslint-cjs-to-esm [ESLint Arguments!]

Run Lint

npx eslint-cjs-to-esm "./src/**/*.{js,ts}"

Fix Errors

npx eslint-cjs-to-esm "./src/**/*.{js,ts}" --fix

Warning You need to start with . for relative path. It is wrapper limitation.
NG: npx eslint-cjs-to-esm "src/**/*.ts"
OK: npx eslint-cjs-to-esm "./src/**/*.ts"

DEBUG:

DEBUG=eslint-cjs-to-esm npx eslint-cjs-to-esm "./src/**/*.{js,ts}"

Rules

This rule set is based on ESLint rules for migrating projects from CommonJS to ESM.

eslint-plugin-file-extension-in-import-ts

eslint-plugin-node

ESLint PluginRuleSourceDescriptionFixable
nodeno-extraneous-import:link:disallow import declarations which import extraneous modules-
nodeno-sync:link:disallow synchronous methods-
nodefile-extension-in-import:link:enforce the style of file extensions in import declarationsYes

eslint-plugin-import

ESLint PluginRuleSourceDescriptionFixable
importextensions:link:Ensure consistent use of file extension within the import path.-
importno-unresolved:link:Ensure imports point to a file/module that can be resolved.-
importno-useless-path-segments:link:Prevent unnecessary path segments in import and require statements.Yes
importno-extraneous-dependencies:link:Forbid the use of extraneous packages.-
importno-commonjs:link:Report CommonJS require calls and module.exports or exports.*.-

📝 commonjs-to-es-module-codemod helps you to migrate from require/exports(CJS) to import/export(ESM).

eslint-plugin-unicorn

ESLint PluginRuleSourceDescriptionFixable
unicornprefer-module:link:Prefer JavaScript modules (ESM) over CommonJS.Yes
unicornprefer-node-protocol:link:Prefer using the node: protocol when importing Node.js builtin modules.Yes
unicornprefer-top-level-await:link:Prefer top-level await over top-level promises and async function calls.Suggest

Changelog

See Releases page.

Running tests

Install devDependencies and Run npm test:

npm test

Contributing

Pull requests and stars are always welcome.

For bugs and feature requests, please create an issue.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

License

MIT © azu

3.0.2

3 months ago

3.0.1

3 months ago

3.0.0

5 months ago

2.3.0

6 months ago

2.2.0

10 months ago

2.1.0

10 months ago

2.0.0

1 year ago

1.1.0

1 year ago

1.0.26

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago