diff --git a/.eslintrc.cjs b/.eslintrc.cjs index fd6e9583..24315567 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -1,53 +1,53 @@ -'use strict'; +"use strict"; -const airbnbBase = require('eslint-config-airbnb-base'); +const airbnbBase = require("eslint-config-airbnb-base"); // eslint-disable-next-line import/no-dynamic-require const bestPractices = require(airbnbBase.extends[0]); const ignoredProps = bestPractices.rules[ - 'no-param-reassign' + "no-param-reassign" ][1].ignorePropertyModificationsFor.concat( - 'err', - 'x', - '_', - 'opts', - 'options', - 'settings', - 'config', - 'cfg', + "err", + "x", + "_", + "opts", + "options", + "settings", + "config", + "cfg" ); // Additional rules that are specific and overriding previous const additionalChanges = { - strict: 'off', + strict: "off", // Enforce using named functions when regular function is used, // otherwise use arrow functions - 'func-names': ['error', 'always'], + "func-names": ["error", "always"], // Always use parens (for consistency). // https://eslint.org/docs/rules/arrow-parens - 'arrow-parens': ['error', 'always', { requireForBlockBody: true }], - 'prefer-arrow-callback': [ - 'error', + "arrow-parens": ["error", "always", { requireForBlockBody: true }], + "prefer-arrow-callback": [ + "error", { allowNamedFunctions: true, allowUnboundThis: true }, ], // http://eslint.org/docs/rules/max-params - 'max-params': ['error', { max: 3 }], + "max-params": ["error", { max: 3 }], // http://eslint.org/docs/rules/max-statements - 'max-statements': ['error', { max: 20 }], + "max-statements": ["error", { max: 20 }], // http://eslint.org/docs/rules/max-statements-per-line - 'max-statements-per-line': ['error', { max: 1 }], + "max-statements-per-line": ["error", { max: 1 }], // http://eslint.org/docs/rules/max-nested-callbacks - 'max-nested-callbacks': ['error', { max: 4 }], + "max-nested-callbacks": ["error", { max: 4 }], // http://eslint.org/docs/rules/max-depth - 'max-depth': ['error', { max: 4 }], + "max-depth": ["error", { max: 4 }], // enforces no braces where they can be omitted // https://eslint.org/docs/rules/arrow-body-style // Never enable for object literal. - 'arrow-body-style': [ - 'error', - 'as-needed', + "arrow-body-style": [ + "error", + "as-needed", { requireReturnForObjectLiteral: false }, ], // Allow functions to be use before define because: @@ -55,8 +55,8 @@ const additionalChanges = { // 2) because ensure read flow is from top to bottom // 3) logically order of the code. // 4) the only addition is 'typedefs' option, see overrides for TS files - 'no-use-before-define': [ - 'error', + "no-use-before-define": [ + "error", { functions: false, classes: true, @@ -67,8 +67,8 @@ const additionalChanges = { // disallow reassignment of function parameters // disallow parameter object manipulation except for specific exclusions // rule: https://eslint.org/docs/rules/no-param-reassign.html - 'no-param-reassign': [ - 'error', + "no-param-reassign": [ + "error", { props: true, ignorePropertyModificationsFor: ignoredProps, @@ -76,27 +76,27 @@ const additionalChanges = { ], // disallow declaration of variables that are not used in the code - 'no-unused-vars': [ - 'error', + "no-unused-vars": [ + "error", { ignoreRestSiblings: true, // airbnb's default - vars: 'all', // airbnb's default - varsIgnorePattern: '^(?:$$|xx|_|__|[iI]gnor(?:e|ing|ed))', - args: 'after-used', // airbnb's default - argsIgnorePattern: '^(?:$$|xx|_|__|[iI]gnor(?:e|ing|ed))', + vars: "all", // airbnb's default + varsIgnorePattern: "^(?:$$|xx|_|__|[iI]gnor(?:e|ing|ed))", + args: "after-used", // airbnb's default + argsIgnorePattern: "^(?:$$|xx|_|__|[iI]gnor(?:e|ing|ed))", // catch blocks are handled by Unicorns - caughtErrors: 'none', + caughtErrors: "none", // caughtErrorsIgnorePattern: '^(?:$$|xx|_|__|[iI]gnor(?:e|ing|ed))', }, ], }; const importRules = { - 'import/namespace': ['error', { allowComputed: true }], - 'import/no-absolute-path': 'error', - 'import/no-webpack-loader-syntax': 'error', - 'import/no-self-import': 'error', + "import/namespace": ["error", { allowComputed: true }], + "import/no-absolute-path": "error", + "import/no-webpack-loader-syntax": "error", + "import/no-self-import": "error", // Enable this sometime in the future when Node.js has ES2015 module support // 'import/no-cycle': 'error', @@ -104,8 +104,8 @@ const importRules = { // Disabled as it doesn't work with TypeScript // 'import/newline-after-import': 'error', - 'import/no-amd': 'error', - 'import/no-duplicates': 'error', + "import/no-amd": "error", + "import/no-duplicates": "error", // Enable this sometime in the future when Node.js has ES2015 module support // 'import/unambiguous': 'error', @@ -116,10 +116,10 @@ const importRules = { // Looks useful, but too unstable at the moment // 'import/no-deprecated': 'error', - 'import/no-extraneous-dependencies': 'off', - 'import/no-mutable-exports': 'error', - 'import/no-named-as-default-member': 'error', - 'import/no-named-as-default': 'error', + "import/no-extraneous-dependencies": "off", + "import/no-mutable-exports": "error", + "import/no-named-as-default-member": "error", + "import/no-named-as-default": "error", // Disabled because it's buggy and it also doesn't work with TypeScript // 'import/no-unresolved': [ @@ -129,32 +129,32 @@ const importRules = { // } // ], - 'import/order': 'error', - 'import/no-unassigned-import': [ - 'error', - { allow: ['@babel/polyfill', '@babel/register'] }, + "import/order": "error", + "import/no-unassigned-import": [ + "error", + { allow: ["@babel/polyfill", "@babel/register"] }, ], - 'import/prefer-default-export': 'off', + "import/prefer-default-export": "off", // Ensure more web-compat // ! note that it doesn't work in CommonJS // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md - 'import/extensions': 'off', + "import/extensions": "off", // ? Always use named exports. Enable? // 'import/no-default-export': 'error', // ? enable? - 'import/exports-last': 'off', + "import/exports-last": "off", // todo: Enable in future. // Ensures everything is tested (all exports should be used). // For cases when you don't want or can't test, add eslint-ignore comment! // see: https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unused-modules.md - 'import/no-unused-modules': 'off', + "import/no-unused-modules": "off", - 'import/no-useless-path-segments': ['error', { noUselessIndex: false }], + "import/no-useless-path-segments": ["error", { noUselessIndex: false }], }; module.exports = { @@ -165,8 +165,8 @@ module.exports = { node: true, commonjs: true, }, - extends: ['eslint:recommended', 'airbnb-base', 'plugin:prettier/recommended'], - plugins: ['prettier'], + extends: ["eslint:recommended", "airbnb-base", "plugin:prettier/recommended"], + plugins: ["prettier"], rules: { ...additionalChanges, ...importRules, diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 38a96784..d504a4d0 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -2,7 +2,6 @@ version: 2 updates: - # Maintain dependencies for GitHub Actions - package-ecosystem: "github-actions" directory: "/" diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 47c50394..7cc44b6e 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -13,12 +13,12 @@ name: "CodeQL" on: push: - branches: [ master ] + branches: [master] pull_request: # The branches below must be a subset of the branches above - branches: [ master ] + branches: [master] schedule: - - cron: '0 2 * * *' + - cron: "0 2 * * *" jobs: analyze: @@ -32,39 +32,39 @@ jobs: strategy: fail-fast: false matrix: - language: [ 'javascript' ] + language: ["javascript"] # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] # Learn more about CodeQL language support at https://git.io/codeql-language-support steps: - - name: Checkout repository - uses: actions/checkout@v5 + - name: Checkout repository + uses: actions/checkout@v5 - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v3 + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v3 - # ℹ️ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl + # ℹ️ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl - # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language + # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language - #- run: | - # make bootstrap - # make release + #- run: | + # make bootstrap + # make release - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1ada2cea..294042b6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -52,10 +52,10 @@ name: ci on: push: branches: - - '*' + - "*" pull_request: branches: - - '*' + - "*" jobs: build-and-test: @@ -65,7 +65,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] - node-version: [18, 20, 22, 'lts/*'] + node-version: [18, 20, 22, "lts/*"] steps: - name: Checkout diff --git a/.prettierignore b/.prettierignore index e0d0cdf8..a5ba8285 100644 --- a/.prettierignore +++ b/.prettierignore @@ -8,6 +8,8 @@ !*.md* !*.y*ml +pnpm-lock.yaml + !**/src !**/src/** diff --git a/.prettierrc.cjs b/.prettierrc.cjs new file mode 100644 index 00000000..823cf706 --- /dev/null +++ b/.prettierrc.cjs @@ -0,0 +1,23 @@ +"use strict"; + +const config = require("@tunnckocore/prettier-config"); + +module.exports = { + ...config, + overrides: [ + { + files: ["**/*.md*"], + options: { + proseWrap: "always", + printWidth: 80, + }, + }, + { + files: ["**/.all-contributorsrc"], + options: { + parser: "json-stringify", + singleQuote: false, + }, + }, + ], +}; diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index 88a5da2e..00000000 --- a/.prettierrc.js +++ /dev/null @@ -1,23 +0,0 @@ -'use strict'; - -const config = require('@tunnckocore/prettier-config'); - -module.exports = { - ...config, - overrides: [ - { - files: ['**/*.md*'], - options: { - proseWrap: 'always', - printWidth: 80, - }, - }, - { - files: ['**/.all-contributorsrc'], - options: { - parser: 'json-stringify', - singleQuote: false, - }, - }, - ], -}; diff --git a/README.md b/README.md index 0efe3ec0..700b0c4c 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ [![Code style][codestyle-img]][codestyle-url] [![linux build status][linux-build-img]][build-url] [![macos build status][macos-build-img]][build-url] + If you have any _how-to_ kind of questions, please read the [Contributing @@ -21,6 +22,7 @@ at Twitter. [![Minimum Required Nodejs][nodejs-img]][npmv-url] [![Buy me a Kofi][kofi-img]][kofi-url] [![Make A Pull Request][prs-welcome-img]][prs-welcome-url] + @@ -49,7 +51,7 @@ use._ --> ## Project Status: Maintained > [!NOTE] -> Check [VERSION NOTES](https://github.com/node-formidable/formidable/blob/master/VERSION_NOTES.md) for more information on v1, v2, and v3 plans, NPM dist-tags and branches._ +> Check [VERSION NOTES](https://github.com/node-formidable/formidable/blob/master/VERSION_NOTES.md) for more information on v1, v2, and v3 plans, NPM dist-tags and branches.\_ This module was initially developed by [**@felixge**](https://github.com/felixge) for @@ -95,7 +97,6 @@ npm install formidable@v3 _**Note:** Future not ready releases will be published on `*-next` dist-tags for the corresponding version._ - ## Examples For more examples look at the `examples/` directory. @@ -106,34 +107,33 @@ Parse an incoming file upload, with the [Node.js's built-in `http` module](https://nodejs.org/api/http.html). ```js -import http from 'node:http'; -import formidable, {errors as formidableErrors} from 'formidable'; +import http from "node:http"; +import formidable, { errors as formidableErrors } from "formidable"; const server = http.createServer(async (req, res) => { - if (req.url === '/api/upload' && req.method.toLowerCase() === 'post') { + if (req.url === "/api/upload" && req.method.toLowerCase() === "post") { // parse a file upload const form = formidable({}); let fields; let files; try { - [fields, files] = await form.parse(req); + [fields, files] = await form.parse(req); } catch (err) { - // example to check for a very specific error - if (err.code === formidableErrors.maxFieldsExceeded) { - - } - console.error(err); - res.writeHead(err.httpCode || 400, { 'Content-Type': 'text/plain' }); - res.end(String(err)); - return; + // example to check for a very specific error + if (err.code === formidableErrors.maxFieldsExceeded) { + } + console.error(err); + res.writeHead(err.httpCode || 400, { "Content-Type": "text/plain" }); + res.end(String(err)); + return; } - res.writeHead(200, { 'Content-Type': 'application/json' }); + res.writeHead(200, { "Content-Type": "application/json" }); res.end(JSON.stringify({ fields, files }, null, 2)); return; } // show a file upload form - res.writeHead(200, { 'Content-Type': 'text/html' }); + res.writeHead(200, { "Content-Type": "text/html" }); res.end(`
"http" module"http" module"express" npm package