routie dev init since i didn't adhere to any proper guidance up until now
This commit is contained in:
+201
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
# ESLint Compatibility Utilities
|
||||
|
||||
## Overview
|
||||
|
||||
This package contains functions that allow you to wrap existing ESLint rules, plugins, and configurations that were intended for use with ESLint v8.x or v9.x to allow them to work as-is in ESLint v9.x and v10.x.
|
||||
|
||||
**Note:** All plugins are not guaranteed to work in ESLint v9.x or v10.x. This package fixes the most common issues but can't fix everything.
|
||||
|
||||
## Installation
|
||||
|
||||
For Node.js and compatible runtimes:
|
||||
|
||||
```shell
|
||||
npm install @eslint/compat -D
|
||||
# or
|
||||
yarn add @eslint/compat -D
|
||||
# or
|
||||
pnpm install @eslint/compat -D
|
||||
# or
|
||||
bun add @eslint/compat -D
|
||||
```
|
||||
|
||||
For Deno:
|
||||
|
||||
```shell
|
||||
deno add @eslint/compat
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
This package exports the following functions in both ESM and CommonJS format:
|
||||
|
||||
- `fixupRule(rule)` - wraps the given rule in a compatibility layer and returns the result
|
||||
- `fixupPluginRules(plugin)` - wraps each rule in the given plugin using `fixupRule()` and returns a new object that represents the plugin with the fixed-up rules
|
||||
- `fixupConfigRules(configs)` - wraps all plugins found in an array of config objects using `fixupPluginRules()`
|
||||
- `includeIgnoreFile(path)` - reads an ignore file (like `.gitignore`) and converts the patterns into the correct format for the config file
|
||||
|
||||
### Fixing Rules
|
||||
|
||||
If you have a rule that you'd like to make compatible with ESLint v9.x or v10.x, you can do so using the `fixupRule()` function:
|
||||
|
||||
```js
|
||||
// ESM example
|
||||
import { fixupRule } from "@eslint/compat";
|
||||
|
||||
// Step 1: Import your rule
|
||||
import myRule from "./local-rule.js";
|
||||
|
||||
// Step 2: Create backwards-compatible rule
|
||||
const compatRule = fixupRule(myRule);
|
||||
|
||||
// Step 3 (optional): Export fixed rule
|
||||
export default compatRule;
|
||||
```
|
||||
|
||||
Or in CommonJS:
|
||||
|
||||
```js
|
||||
// CommonJS example
|
||||
const { fixupRule } = require("@eslint/compat");
|
||||
|
||||
// Step 1: Import your rule
|
||||
const myRule = require("./local-rule.js");
|
||||
|
||||
// Step 2: Create backwards-compatible rule
|
||||
const compatRule = fixupRule(myRule);
|
||||
|
||||
// Step 3 (optional): Export fixed rule
|
||||
module.exports = compatRule;
|
||||
```
|
||||
|
||||
### Fixing Plugins
|
||||
|
||||
If you are using a plugin in your `eslint.config.js` that is not yet compatible with ESLint v9.x or v10.x, you can wrap it using the `fixupPluginRules()` function:
|
||||
|
||||
```js
|
||||
// eslint.config.js - ESM example
|
||||
import { defineConfig } from "eslint/config";
|
||||
import { fixupPluginRules } from "@eslint/compat";
|
||||
import somePlugin from "eslint-plugin-some-plugin";
|
||||
|
||||
export default defineConfig([
|
||||
{
|
||||
plugins: {
|
||||
// insert the fixed plugin instead of the original
|
||||
somePlugin: fixupPluginRules(somePlugin),
|
||||
},
|
||||
rules: {
|
||||
"somePlugin/rule-name": "error",
|
||||
},
|
||||
},
|
||||
]);
|
||||
```
|
||||
|
||||
Or in CommonJS:
|
||||
|
||||
```js
|
||||
// eslint.config.js - CommonJS example
|
||||
const { defineConfig } = require("eslint/config");
|
||||
const { fixupPluginRules } = require("@eslint/compat");
|
||||
const somePlugin = require("eslint-plugin-some-plugin");
|
||||
|
||||
module.exports = defineConfig([
|
||||
{
|
||||
plugins: {
|
||||
// insert the fixed plugin instead of the original
|
||||
somePlugin: fixupPluginRules(somePlugin),
|
||||
},
|
||||
rules: {
|
||||
"somePlugin/rule-name": "error",
|
||||
},
|
||||
},
|
||||
]);
|
||||
```
|
||||
|
||||
### Fixing Configs
|
||||
|
||||
If you are importing other configs into your `eslint.config.js` that use plugins that are not yet compatible with ESLint v9.x or v10.x, you can wrap the entire array or a single object using the `fixupConfigRules()` function:
|
||||
|
||||
```js
|
||||
// eslint.config.js - ESM example
|
||||
import { defineConfig } from "eslint/config";
|
||||
import { fixupConfigRules } from "@eslint/compat";
|
||||
import someConfig from "eslint-config-some-config";
|
||||
|
||||
export default defineConfig([
|
||||
...fixupConfigRules(someConfig),
|
||||
{
|
||||
// your overrides
|
||||
},
|
||||
]);
|
||||
```
|
||||
|
||||
Or in CommonJS:
|
||||
|
||||
```js
|
||||
// eslint.config.js - CommonJS example
|
||||
const { defineConfig } = require("eslint/config");
|
||||
const { fixupConfigRules } = require("@eslint/compat");
|
||||
const someConfig = require("eslint-config-some-config");
|
||||
|
||||
module.exports = defineConfig([
|
||||
...fixupConfigRules(someConfig),
|
||||
{
|
||||
// your overrides
|
||||
},
|
||||
]);
|
||||
```
|
||||
|
||||
### Including Ignore Files
|
||||
|
||||
If you were using an alternate ignore file in ESLint v8.x, such as using `--ignore-path .gitignore` on the command line, you can include those patterns programmatically in your config file using the `includeIgnoreFile()` function.
|
||||
|
||||
The `includeIgnoreFile()` function also accepts a second optional `name` parameter that allows you to set a custom name for this configuration object. If not specified, it defaults to `"Imported .gitignore patterns"`. For example:
|
||||
|
||||
```js
|
||||
// eslint.config.js - ESM example
|
||||
import { defineConfig } from "eslint/config";
|
||||
import { includeIgnoreFile } from "@eslint/compat";
|
||||
import path from "node:path";
|
||||
|
||||
const gitignorePath = path.resolve(import.meta.dirname, ".gitignore");
|
||||
|
||||
export default defineConfig([
|
||||
includeIgnoreFile(gitignorePath, "Imported .gitignore patterns"), // second argument is optional.
|
||||
{
|
||||
// your overrides
|
||||
},
|
||||
]);
|
||||
```
|
||||
|
||||
Or in CommonJS:
|
||||
|
||||
```js
|
||||
// eslint.config.js - CommonJS example
|
||||
const { defineConfig } = require("eslint/config");
|
||||
const { includeIgnoreFile } = require("@eslint/compat");
|
||||
const path = require("node:path");
|
||||
const gitignorePath = path.resolve(__dirname, ".gitignore");
|
||||
|
||||
module.exports = defineConfig([
|
||||
includeIgnoreFile(gitignorePath, "Imported .gitignore patterns"), // second argument is optional.
|
||||
{
|
||||
// your overrides
|
||||
},
|
||||
]);
|
||||
```
|
||||
|
||||
**Limitation:** This works without modification when the ignore file is in the same directory as your config file. If the ignore file is in a different directory, you may need to modify the patterns manually.
|
||||
|
||||
## License
|
||||
|
||||
Apache 2.0
|
||||
|
||||
<!-- NOTE: This section is autogenerated. Do not manually edit.-->
|
||||
<!--sponsorsstart-->
|
||||
|
||||
## Sponsors
|
||||
|
||||
The following companies, organizations, and individuals support ESLint's ongoing maintenance and development. [Become a Sponsor](https://eslint.org/donate)
|
||||
to get your logo on our READMEs and [website](https://eslint.org/sponsors).
|
||||
|
||||
<h3>Platinum Sponsors</h3>
|
||||
<p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="128"></a></p><h3>Gold Sponsors</h3>
|
||||
<p><a href="https://qlty.sh/"><img src="https://images.opencollective.com/qltysh/33d157d/logo.png" alt="Qlty Software" height="96"></a></p><h3>Silver Sponsors</h3>
|
||||
<p><a href="https://vite.dev/"><img src="https://images.opencollective.com/vite/d472863/logo.png" alt="Vite" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/2d6c3b6/logo.png" alt="Liftoff" height="64"></a> <a href="https://stackblitz.com"><img src="https://avatars.githubusercontent.com/u/28635252" alt="StackBlitz" height="64"></a></p><h3>Bronze Sponsors</h3>
|
||||
<p><a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://opensource.sap.com"><img src="https://avatars.githubusercontent.com/u/2531208" alt="SAP" height="32"></a> <a href="https://www.crawljobs.com/"><img src="https://images.opencollective.com/crawljobs-poland/fa43a17/logo.png" alt="CrawlJobs" height="32"></a> <a href="#"><img src="https://images.opencollective.com/aeriusventilations-org/avatar.png" alt="aeriusventilation's Org" height="32"></a> <a href="https://depot.dev"><img src="https://images.opencollective.com/depot/39125a1/logo.png" alt="Depot" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340" alt="GitBook" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774" alt="HeroCoders" height="32"></a> <a href="https://www.lambdatest.com"><img src="https://avatars.githubusercontent.com/u/171592363" alt="TestMu AI Open Source Office (Formerly LambdaTest)" height="32"></a></p>
|
||||
<h3>Technology Sponsors</h3>
|
||||
Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.
|
||||
<p><a href="https://netlify.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/netlify-icon.svg" alt="Netlify" height="32"></a> <a href="https://algolia.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/algolia-icon.svg" alt="Algolia" height="32"></a> <a href="https://1password.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/1password-icon.svg" alt="1Password" height="32"></a></p>
|
||||
<!--sponsorsend-->
|
||||
+563
@@ -0,0 +1,563 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('node:fs');
|
||||
var path = require('node:path');
|
||||
|
||||
/**
|
||||
* @fileoverview Functions to fix up rules to provide missing methods on the `context` and `sourceCode` objects.
|
||||
* @author Nicholas C. Zakas
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Types
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** @typedef {import("@eslint/core").Plugin} FixupPluginDefinition */
|
||||
/** @typedef {import("@eslint/core").RuleDefinition} FixupRuleDefinition */
|
||||
/** @typedef {FixupRuleDefinition["create"]} FixupLegacyRuleDefinition */
|
||||
/** @typedef {import("@eslint/core").ConfigObject} FixupConfig */
|
||||
/** @typedef {Array<FixupConfig>} FixupConfigArray */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Data
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The removed methods from the `context` object that need to be added back.
|
||||
* The keys are the name of the method on the `context` object and the values
|
||||
* are the name of the method on the `sourceCode` object.
|
||||
* @type {Map<string, string>}
|
||||
*/
|
||||
const removedMethodNames = new Map([
|
||||
["getSource", "getText"],
|
||||
["getSourceLines", "getLines"],
|
||||
["getAllComments", "getAllComments"],
|
||||
["getDeclaredVariables", "getDeclaredVariables"],
|
||||
["getNodeByRangeIndex", "getNodeByRangeIndex"],
|
||||
["getCommentsBefore", "getCommentsBefore"],
|
||||
["getCommentsAfter", "getCommentsAfter"],
|
||||
["getCommentsInside", "getCommentsInside"],
|
||||
["getJSDocComment", "getJSDocComment"],
|
||||
["getFirstToken", "getFirstToken"],
|
||||
["getFirstTokens", "getFirstTokens"],
|
||||
["getLastToken", "getLastToken"],
|
||||
["getLastTokens", "getLastTokens"],
|
||||
["getTokenAfter", "getTokenAfter"],
|
||||
["getTokenBefore", "getTokenBefore"],
|
||||
["getTokenByRangeStart", "getTokenByRangeStart"],
|
||||
["getTokens", "getTokens"],
|
||||
["getTokensAfter", "getTokensAfter"],
|
||||
["getTokensBefore", "getTokensBefore"],
|
||||
["getTokensBetween", "getTokensBetween"],
|
||||
]);
|
||||
|
||||
/**
|
||||
* Tracks the original rule definition and the fixed-up rule definition.
|
||||
* @type {WeakMap<FixupRuleDefinition|FixupLegacyRuleDefinition,FixupRuleDefinition>}
|
||||
*/
|
||||
const fixedUpRuleReplacements = new WeakMap();
|
||||
|
||||
/**
|
||||
* Tracks all of the fixed up rule definitions so we don't duplicate effort.
|
||||
* @type {WeakSet<FixupRuleDefinition>}
|
||||
*/
|
||||
const fixedUpRules = new WeakSet();
|
||||
|
||||
/**
|
||||
* Tracks the original plugin definition and the fixed-up plugin definition.
|
||||
* @type {WeakMap<FixupPluginDefinition,FixupPluginDefinition>}
|
||||
*/
|
||||
const fixedUpPluginReplacements = new WeakMap();
|
||||
|
||||
/**
|
||||
* Tracks all of the fixed up plugin definitions so we don't duplicate effort.
|
||||
* @type {WeakSet<FixupPluginDefinition>}
|
||||
*/
|
||||
const fixedUpPlugins = new WeakSet();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Determines if two nodes or tokens overlap.
|
||||
* @param {object} first The first node or token to check.
|
||||
* @param {object} second The second node or token to check.
|
||||
* @returns {boolean} True if the two nodes or tokens overlap.
|
||||
*/
|
||||
function nodesOrTokensOverlap(first, second) {
|
||||
return (
|
||||
(first.range[0] <= second.range[0] &&
|
||||
first.range[1] >= second.range[0]) ||
|
||||
(second.range[0] <= first.range[0] && second.range[1] >= first.range[0])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a node is an export declaration.
|
||||
* @param {object} node An AST node.
|
||||
* @returns {boolean} True if the node is an export declaration.
|
||||
*/
|
||||
function looksLikeExport(node) {
|
||||
return (
|
||||
node.type === "ExportDefaultDeclaration" ||
|
||||
node.type === "ExportNamedDeclaration"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for the presence of a JSDoc comment for the given node and returns it.
|
||||
* @param {object} node The AST node to get the comment for.
|
||||
* @param {object} sourceCode A SourceCode instance to get comments.
|
||||
* @returns {object|null} The Block comment token containing the JSDoc comment
|
||||
* for the given node or null if not found.
|
||||
*/
|
||||
function findJSDocComment(node, sourceCode) {
|
||||
const tokenBefore = sourceCode.getTokenBefore(node, {
|
||||
includeComments: true,
|
||||
});
|
||||
|
||||
if (
|
||||
tokenBefore &&
|
||||
tokenBefore.type === "Block" &&
|
||||
tokenBefore.value.charAt(0) === "*" &&
|
||||
node.loc.start.line - tokenBefore.loc.end.line <= 1
|
||||
) {
|
||||
return tokenBefore;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exports
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Takes the given rule and creates a new rule with the `create()` method wrapped
|
||||
* to provide missing methods on the `context` and `sourceCode` objects.
|
||||
* @param {FixupRuleDefinition|FixupLegacyRuleDefinition} ruleDefinition The rule to fix up.
|
||||
* @returns {FixupRuleDefinition} The fixed-up rule.
|
||||
*/
|
||||
function fixupRule(ruleDefinition) {
|
||||
// first check if we've already fixed up this rule
|
||||
if (fixedUpRuleReplacements.has(ruleDefinition)) {
|
||||
return fixedUpRuleReplacements.get(ruleDefinition);
|
||||
}
|
||||
|
||||
const isLegacyRule = typeof ruleDefinition === "function";
|
||||
|
||||
// check to see if this rule definition has already been fixed up
|
||||
if (!isLegacyRule && fixedUpRules.has(ruleDefinition)) {
|
||||
return ruleDefinition;
|
||||
}
|
||||
|
||||
const originalCreate = isLegacyRule
|
||||
? ruleDefinition
|
||||
: ruleDefinition.create.bind(ruleDefinition);
|
||||
|
||||
function ruleCreate(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
// No need to create old methods for ESLint < 9
|
||||
if ("getScope" in context) {
|
||||
return originalCreate(context);
|
||||
}
|
||||
|
||||
let eslintVersion = 9;
|
||||
if (!("getCwd" in context)) {
|
||||
eslintVersion = 10;
|
||||
}
|
||||
|
||||
let compatSourceCode = sourceCode;
|
||||
if (eslintVersion >= 10) {
|
||||
compatSourceCode = Object.assign(Object.create(sourceCode), {
|
||||
getTokenOrCommentBefore(node, skip) {
|
||||
return sourceCode.getTokenBefore(node, {
|
||||
includeComments: true,
|
||||
skip,
|
||||
});
|
||||
},
|
||||
getTokenOrCommentAfter(node, skip) {
|
||||
return sourceCode.getTokenAfter(node, {
|
||||
includeComments: true,
|
||||
skip,
|
||||
});
|
||||
},
|
||||
isSpaceBetweenTokens(first, second) {
|
||||
if (nodesOrTokensOverlap(first, second)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const [startingNodeOrToken, endingNodeOrToken] =
|
||||
first.range[1] <= second.range[0]
|
||||
? [first, second]
|
||||
: [second, first];
|
||||
const firstToken =
|
||||
sourceCode.getLastToken(startingNodeOrToken) ||
|
||||
startingNodeOrToken;
|
||||
const finalToken =
|
||||
sourceCode.getFirstToken(endingNodeOrToken) ||
|
||||
endingNodeOrToken;
|
||||
let currentToken = firstToken;
|
||||
|
||||
while (currentToken !== finalToken) {
|
||||
const nextToken = sourceCode.getTokenAfter(
|
||||
currentToken,
|
||||
{
|
||||
includeComments: true,
|
||||
},
|
||||
);
|
||||
|
||||
if (
|
||||
currentToken.range[1] !== nextToken.range[0] ||
|
||||
(nextToken !== finalToken &&
|
||||
nextToken.type === "JSXText" &&
|
||||
/\s/u.test(nextToken.value))
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
currentToken = nextToken;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
getJSDocComment(node) {
|
||||
let parent = node.parent;
|
||||
|
||||
switch (node.type) {
|
||||
case "ClassDeclaration":
|
||||
case "FunctionDeclaration":
|
||||
return findJSDocComment(
|
||||
looksLikeExport(parent) ? parent : node,
|
||||
sourceCode,
|
||||
);
|
||||
|
||||
case "ClassExpression":
|
||||
return findJSDocComment(parent.parent, sourceCode);
|
||||
|
||||
case "ArrowFunctionExpression":
|
||||
case "FunctionExpression":
|
||||
if (
|
||||
parent.type !== "CallExpression" &&
|
||||
parent.type !== "NewExpression"
|
||||
) {
|
||||
while (
|
||||
!sourceCode.getCommentsBefore(parent)
|
||||
.length &&
|
||||
!/Function/u.test(parent.type) &&
|
||||
parent.type !== "MethodDefinition" &&
|
||||
parent.type !== "Property"
|
||||
) {
|
||||
parent = parent.parent;
|
||||
|
||||
if (!parent) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
parent &&
|
||||
parent.type !== "FunctionDeclaration" &&
|
||||
parent.type !== "Program"
|
||||
) {
|
||||
return findJSDocComment(parent, sourceCode);
|
||||
}
|
||||
}
|
||||
|
||||
return findJSDocComment(node, sourceCode);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Object.freeze(compatSourceCode);
|
||||
}
|
||||
|
||||
let currentNode = compatSourceCode.ast;
|
||||
|
||||
const compatContext = Object.assign(Object.create(context), {
|
||||
parserServices: compatSourceCode.parserServices,
|
||||
|
||||
/*
|
||||
* The following methods rely on the current node in the traversal,
|
||||
* so we need to add them manually.
|
||||
*/
|
||||
getScope() {
|
||||
return compatSourceCode.getScope(currentNode);
|
||||
},
|
||||
|
||||
getAncestors() {
|
||||
return compatSourceCode.getAncestors(currentNode);
|
||||
},
|
||||
|
||||
markVariableAsUsed(variable) {
|
||||
compatSourceCode.markVariableAsUsed(variable, currentNode);
|
||||
},
|
||||
});
|
||||
|
||||
if (eslintVersion >= 10) {
|
||||
Object.assign(compatContext, {
|
||||
parserOptions: compatContext.languageOptions.parserOptions,
|
||||
|
||||
getCwd() {
|
||||
return compatContext.cwd;
|
||||
},
|
||||
|
||||
getFilename() {
|
||||
return compatContext.filename;
|
||||
},
|
||||
|
||||
getPhysicalFilename() {
|
||||
return compatContext.physicalFilename;
|
||||
},
|
||||
|
||||
getSourceCode() {
|
||||
return compatSourceCode;
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(compatContext, "sourceCode", {
|
||||
enumerable: true,
|
||||
value: compatSourceCode,
|
||||
});
|
||||
}
|
||||
|
||||
// add passthrough methods
|
||||
for (const [
|
||||
contextMethodName,
|
||||
sourceCodeMethodName,
|
||||
] of removedMethodNames) {
|
||||
compatContext[contextMethodName] =
|
||||
compatSourceCode[sourceCodeMethodName].bind(compatSourceCode);
|
||||
}
|
||||
|
||||
// freeze just like the original context
|
||||
Object.freeze(compatContext);
|
||||
|
||||
/*
|
||||
* Create the visitor object using the original create() method.
|
||||
* This is necessary to ensure that the visitor object is created
|
||||
* with the correct context.
|
||||
*/
|
||||
const visitor = originalCreate(compatContext);
|
||||
|
||||
/*
|
||||
* Wrap each method in the visitor object to update the currentNode
|
||||
* before calling the original method. This is necessary because the
|
||||
* methods like `getScope()` need to know the current node.
|
||||
*/
|
||||
for (const [methodName, method] of Object.entries(visitor)) {
|
||||
/*
|
||||
* Node is the second argument to most code path methods,
|
||||
* and the third argument for onCodePathSegmentLoop.
|
||||
*/
|
||||
if (methodName.startsWith("on")) {
|
||||
// eslint-disable-next-line no-loop-func -- intentionally updating shared `currentNode` variable
|
||||
visitor[methodName] = (...args) => {
|
||||
currentNode =
|
||||
args[methodName === "onCodePathSegmentLoop" ? 2 : 1];
|
||||
|
||||
return method.call(visitor, ...args);
|
||||
};
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-loop-func -- intentionally updating shared `currentNode` variable
|
||||
visitor[methodName] = (...args) => {
|
||||
currentNode = args[0];
|
||||
|
||||
return method.call(visitor, ...args);
|
||||
};
|
||||
}
|
||||
|
||||
return visitor;
|
||||
}
|
||||
|
||||
const newRuleDefinition = {
|
||||
...(isLegacyRule ? undefined : ruleDefinition),
|
||||
create: ruleCreate,
|
||||
};
|
||||
|
||||
// copy `schema` property of function-style rule or top-level `schema` property of object-style rule into `meta` object
|
||||
// @ts-ignore -- top-level `schema` property was not officially supported for object-style rules so it doesn't exist in types
|
||||
const { schema } = ruleDefinition;
|
||||
if (schema) {
|
||||
if (!newRuleDefinition.meta) {
|
||||
newRuleDefinition.meta = { schema };
|
||||
} else {
|
||||
newRuleDefinition.meta = {
|
||||
...newRuleDefinition.meta,
|
||||
// top-level `schema` had precedence over `meta.schema` so it's okay to overwrite `meta.schema` if it exists
|
||||
schema,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// cache the fixed up rule
|
||||
fixedUpRuleReplacements.set(ruleDefinition, newRuleDefinition);
|
||||
fixedUpRules.add(newRuleDefinition);
|
||||
|
||||
return newRuleDefinition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes the given plugin and creates a new plugin with all of the rules wrapped
|
||||
* to provide missing methods on the `context` and `sourceCode` objects.
|
||||
* @param {FixupPluginDefinition} plugin The plugin to fix up.
|
||||
* @returns {FixupPluginDefinition} The fixed-up plugin.
|
||||
*/
|
||||
function fixupPluginRules(plugin) {
|
||||
// first check if we've already fixed up this plugin
|
||||
if (fixedUpPluginReplacements.has(plugin)) {
|
||||
return fixedUpPluginReplacements.get(plugin);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the plugin has already been fixed up, or if the plugin
|
||||
* doesn't have any rules, we can just return it.
|
||||
*/
|
||||
if (fixedUpPlugins.has(plugin) || !plugin.rules) {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
const newPlugin = {
|
||||
...plugin,
|
||||
rules: Object.fromEntries(
|
||||
Object.entries(plugin.rules).map(([ruleId, ruleDefinition]) => [
|
||||
ruleId,
|
||||
fixupRule(ruleDefinition),
|
||||
]),
|
||||
),
|
||||
};
|
||||
|
||||
// cache the fixed up plugin
|
||||
fixedUpPluginReplacements.set(plugin, newPlugin);
|
||||
fixedUpPlugins.add(newPlugin);
|
||||
|
||||
return newPlugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes the given configuration and creates a new configuration with all of the
|
||||
* rules wrapped to provide missing methods on the `context` and `sourceCode` objects.
|
||||
* @param {FixupConfigArray|FixupConfig} config The configuration to fix up.
|
||||
* @returns {FixupConfigArray} The fixed-up configuration.
|
||||
*/
|
||||
function fixupConfigRules(config) {
|
||||
const configs = Array.isArray(config) ? config : [config];
|
||||
|
||||
return configs.map(configItem => {
|
||||
if (!configItem.plugins) {
|
||||
return configItem;
|
||||
}
|
||||
|
||||
const newPlugins = Object.fromEntries(
|
||||
Object.entries(configItem.plugins).map(([pluginName, plugin]) => [
|
||||
pluginName,
|
||||
fixupPluginRules(plugin),
|
||||
]),
|
||||
);
|
||||
|
||||
return {
|
||||
...configItem,
|
||||
plugins: newPlugins,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @fileoverview Ignore file utilities for the compat package.
|
||||
* @author Nicholas C. Zakas
|
||||
*/
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Types
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** @typedef {import("@eslint/core").ConfigObject} FlatConfig */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exports
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Converts an ESLint ignore pattern to a minimatch pattern.
|
||||
* @param {string} pattern The .eslintignore or .gitignore pattern to convert.
|
||||
* @returns {string} The converted pattern.
|
||||
*/
|
||||
function convertIgnorePatternToMinimatch(pattern) {
|
||||
const isNegated = pattern.startsWith("!");
|
||||
const negatedPrefix = isNegated ? "!" : "";
|
||||
const patternToTest = (isNegated ? pattern.slice(1) : pattern).trimEnd();
|
||||
|
||||
// special cases
|
||||
if (["", "**", "/**", "**/"].includes(patternToTest)) {
|
||||
return `${negatedPrefix}${patternToTest}`;
|
||||
}
|
||||
|
||||
const firstIndexOfSlash = patternToTest.indexOf("/");
|
||||
|
||||
const matchEverywherePrefix =
|
||||
firstIndexOfSlash < 0 || firstIndexOfSlash === patternToTest.length - 1
|
||||
? "**/"
|
||||
: "";
|
||||
|
||||
const patternWithoutLeadingSlash =
|
||||
firstIndexOfSlash === 0 ? patternToTest.slice(1) : patternToTest;
|
||||
|
||||
/*
|
||||
* Escape `{` and `(` because in gitignore patterns they are just
|
||||
* literal characters without any specific syntactic meaning,
|
||||
* while in minimatch patterns they can form brace expansion or extglob syntax.
|
||||
*
|
||||
* For example, gitignore pattern `src/{a,b}.js` ignores file `src/{a,b}.js`.
|
||||
* But, the same minimatch pattern `src/{a,b}.js` ignores files `src/a.js` and `src/b.js`.
|
||||
* Minimatch pattern `src/\{a,b}.js` is equivalent to gitignore pattern `src/{a,b}.js`.
|
||||
*/
|
||||
const escapedPatternWithoutLeadingSlash =
|
||||
patternWithoutLeadingSlash.replaceAll(
|
||||
// eslint-disable-next-line regexp/no-empty-lookarounds-assertion -- False positive
|
||||
/(?=((?:\\.|[^{(])*))\1([{(])/guy,
|
||||
"$1\\$2",
|
||||
);
|
||||
|
||||
const matchInsideSuffix = patternToTest.endsWith("/**") ? "/*" : "";
|
||||
|
||||
return `${negatedPrefix}${matchEverywherePrefix}${escapedPatternWithoutLeadingSlash}${matchInsideSuffix}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an ignore file and returns an object with the ignore patterns.
|
||||
* @param {string} ignoreFilePath The absolute path to the ignore file.
|
||||
* @param {string} [name] The name of the ignore file config.
|
||||
* @returns {FlatConfig} An object with an `ignores` property that is an array of ignore patterns.
|
||||
* @throws {Error} If the ignore file path is not an absolute path.
|
||||
*/
|
||||
function includeIgnoreFile(ignoreFilePath, name) {
|
||||
if (!path.isAbsolute(ignoreFilePath)) {
|
||||
throw new Error("The ignore file location must be an absolute path.");
|
||||
}
|
||||
|
||||
const ignoreFile = fs.readFileSync(ignoreFilePath, "utf8");
|
||||
const lines = ignoreFile.split(/\r?\n/u);
|
||||
|
||||
return {
|
||||
name: name || "Imported .gitignore patterns",
|
||||
ignores: lines
|
||||
.map(line => line.trim())
|
||||
.filter(line => line && !line.startsWith("#"))
|
||||
.map(convertIgnorePatternToMinimatch),
|
||||
};
|
||||
}
|
||||
|
||||
exports.convertIgnorePatternToMinimatch = convertIgnorePatternToMinimatch;
|
||||
exports.fixupConfigRules = fixupConfigRules;
|
||||
exports.fixupPluginRules = fixupPluginRules;
|
||||
exports.fixupRule = fixupRule;
|
||||
exports.includeIgnoreFile = includeIgnoreFile;
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
export type FlatConfig = import("@eslint/core").ConfigObject;
|
||||
export type FixupPluginDefinition = import("@eslint/core").Plugin;
|
||||
export type FixupRuleDefinition = import("@eslint/core").RuleDefinition;
|
||||
export type FixupLegacyRuleDefinition = FixupRuleDefinition["create"];
|
||||
export type FixupConfig = import("@eslint/core").ConfigObject;
|
||||
export type FixupConfigArray = Array<FixupConfig>;
|
||||
/**
|
||||
* @fileoverview Ignore file utilities for the compat package.
|
||||
* @author Nicholas C. Zakas
|
||||
*/
|
||||
/** @typedef {import("@eslint/core").ConfigObject} FlatConfig */
|
||||
/**
|
||||
* Converts an ESLint ignore pattern to a minimatch pattern.
|
||||
* @param {string} pattern The .eslintignore or .gitignore pattern to convert.
|
||||
* @returns {string} The converted pattern.
|
||||
*/
|
||||
export function convertIgnorePatternToMinimatch(pattern: string): string;
|
||||
/**
|
||||
* Takes the given configuration and creates a new configuration with all of the
|
||||
* rules wrapped to provide missing methods on the `context` and `sourceCode` objects.
|
||||
* @param {FixupConfigArray|FixupConfig} config The configuration to fix up.
|
||||
* @returns {FixupConfigArray} The fixed-up configuration.
|
||||
*/
|
||||
export function fixupConfigRules(config: FixupConfigArray | FixupConfig): FixupConfigArray;
|
||||
/**
|
||||
* Takes the given plugin and creates a new plugin with all of the rules wrapped
|
||||
* to provide missing methods on the `context` and `sourceCode` objects.
|
||||
* @param {FixupPluginDefinition} plugin The plugin to fix up.
|
||||
* @returns {FixupPluginDefinition} The fixed-up plugin.
|
||||
*/
|
||||
export function fixupPluginRules(plugin: FixupPluginDefinition): FixupPluginDefinition;
|
||||
/**
|
||||
* Takes the given rule and creates a new rule with the `create()` method wrapped
|
||||
* to provide missing methods on the `context` and `sourceCode` objects.
|
||||
* @param {FixupRuleDefinition|FixupLegacyRuleDefinition} ruleDefinition The rule to fix up.
|
||||
* @returns {FixupRuleDefinition} The fixed-up rule.
|
||||
*/
|
||||
export function fixupRule(ruleDefinition: FixupRuleDefinition | FixupLegacyRuleDefinition): FixupRuleDefinition;
|
||||
/**
|
||||
* Reads an ignore file and returns an object with the ignore patterns.
|
||||
* @param {string} ignoreFilePath The absolute path to the ignore file.
|
||||
* @param {string} [name] The name of the ignore file config.
|
||||
* @returns {FlatConfig} An object with an `ignores` property that is an array of ignore patterns.
|
||||
* @throws {Error} If the ignore file path is not an absolute path.
|
||||
*/
|
||||
export function includeIgnoreFile(ignoreFilePath: string, name?: string): FlatConfig;
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
export type FlatConfig = import("@eslint/core").ConfigObject;
|
||||
export type FixupPluginDefinition = import("@eslint/core").Plugin;
|
||||
export type FixupRuleDefinition = import("@eslint/core").RuleDefinition;
|
||||
export type FixupLegacyRuleDefinition = FixupRuleDefinition["create"];
|
||||
export type FixupConfig = import("@eslint/core").ConfigObject;
|
||||
export type FixupConfigArray = Array<FixupConfig>;
|
||||
/**
|
||||
* @fileoverview Ignore file utilities for the compat package.
|
||||
* @author Nicholas C. Zakas
|
||||
*/
|
||||
/** @typedef {import("@eslint/core").ConfigObject} FlatConfig */
|
||||
/**
|
||||
* Converts an ESLint ignore pattern to a minimatch pattern.
|
||||
* @param {string} pattern The .eslintignore or .gitignore pattern to convert.
|
||||
* @returns {string} The converted pattern.
|
||||
*/
|
||||
export function convertIgnorePatternToMinimatch(pattern: string): string;
|
||||
/**
|
||||
* Takes the given configuration and creates a new configuration with all of the
|
||||
* rules wrapped to provide missing methods on the `context` and `sourceCode` objects.
|
||||
* @param {FixupConfigArray|FixupConfig} config The configuration to fix up.
|
||||
* @returns {FixupConfigArray} The fixed-up configuration.
|
||||
*/
|
||||
export function fixupConfigRules(config: FixupConfigArray | FixupConfig): FixupConfigArray;
|
||||
/**
|
||||
* Takes the given plugin and creates a new plugin with all of the rules wrapped
|
||||
* to provide missing methods on the `context` and `sourceCode` objects.
|
||||
* @param {FixupPluginDefinition} plugin The plugin to fix up.
|
||||
* @returns {FixupPluginDefinition} The fixed-up plugin.
|
||||
*/
|
||||
export function fixupPluginRules(plugin: FixupPluginDefinition): FixupPluginDefinition;
|
||||
/**
|
||||
* Takes the given rule and creates a new rule with the `create()` method wrapped
|
||||
* to provide missing methods on the `context` and `sourceCode` objects.
|
||||
* @param {FixupRuleDefinition|FixupLegacyRuleDefinition} ruleDefinition The rule to fix up.
|
||||
* @returns {FixupRuleDefinition} The fixed-up rule.
|
||||
*/
|
||||
export function fixupRule(ruleDefinition: FixupRuleDefinition | FixupLegacyRuleDefinition): FixupRuleDefinition;
|
||||
/**
|
||||
* Reads an ignore file and returns an object with the ignore patterns.
|
||||
* @param {string} ignoreFilePath The absolute path to the ignore file.
|
||||
* @param {string} [name] The name of the ignore file config.
|
||||
* @returns {FlatConfig} An object with an `ignores` property that is an array of ignore patterns.
|
||||
* @throws {Error} If the ignore file path is not an absolute path.
|
||||
*/
|
||||
export function includeIgnoreFile(ignoreFilePath: string, name?: string): FlatConfig;
|
||||
+558
@@ -0,0 +1,558 @@
|
||||
// @ts-self-types="./index.d.ts"
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
/**
|
||||
* @fileoverview Functions to fix up rules to provide missing methods on the `context` and `sourceCode` objects.
|
||||
* @author Nicholas C. Zakas
|
||||
*/
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Types
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** @typedef {import("@eslint/core").Plugin} FixupPluginDefinition */
|
||||
/** @typedef {import("@eslint/core").RuleDefinition} FixupRuleDefinition */
|
||||
/** @typedef {FixupRuleDefinition["create"]} FixupLegacyRuleDefinition */
|
||||
/** @typedef {import("@eslint/core").ConfigObject} FixupConfig */
|
||||
/** @typedef {Array<FixupConfig>} FixupConfigArray */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Data
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The removed methods from the `context` object that need to be added back.
|
||||
* The keys are the name of the method on the `context` object and the values
|
||||
* are the name of the method on the `sourceCode` object.
|
||||
* @type {Map<string, string>}
|
||||
*/
|
||||
const removedMethodNames = new Map([
|
||||
["getSource", "getText"],
|
||||
["getSourceLines", "getLines"],
|
||||
["getAllComments", "getAllComments"],
|
||||
["getDeclaredVariables", "getDeclaredVariables"],
|
||||
["getNodeByRangeIndex", "getNodeByRangeIndex"],
|
||||
["getCommentsBefore", "getCommentsBefore"],
|
||||
["getCommentsAfter", "getCommentsAfter"],
|
||||
["getCommentsInside", "getCommentsInside"],
|
||||
["getJSDocComment", "getJSDocComment"],
|
||||
["getFirstToken", "getFirstToken"],
|
||||
["getFirstTokens", "getFirstTokens"],
|
||||
["getLastToken", "getLastToken"],
|
||||
["getLastTokens", "getLastTokens"],
|
||||
["getTokenAfter", "getTokenAfter"],
|
||||
["getTokenBefore", "getTokenBefore"],
|
||||
["getTokenByRangeStart", "getTokenByRangeStart"],
|
||||
["getTokens", "getTokens"],
|
||||
["getTokensAfter", "getTokensAfter"],
|
||||
["getTokensBefore", "getTokensBefore"],
|
||||
["getTokensBetween", "getTokensBetween"],
|
||||
]);
|
||||
|
||||
/**
|
||||
* Tracks the original rule definition and the fixed-up rule definition.
|
||||
* @type {WeakMap<FixupRuleDefinition|FixupLegacyRuleDefinition,FixupRuleDefinition>}
|
||||
*/
|
||||
const fixedUpRuleReplacements = new WeakMap();
|
||||
|
||||
/**
|
||||
* Tracks all of the fixed up rule definitions so we don't duplicate effort.
|
||||
* @type {WeakSet<FixupRuleDefinition>}
|
||||
*/
|
||||
const fixedUpRules = new WeakSet();
|
||||
|
||||
/**
|
||||
* Tracks the original plugin definition and the fixed-up plugin definition.
|
||||
* @type {WeakMap<FixupPluginDefinition,FixupPluginDefinition>}
|
||||
*/
|
||||
const fixedUpPluginReplacements = new WeakMap();
|
||||
|
||||
/**
|
||||
* Tracks all of the fixed up plugin definitions so we don't duplicate effort.
|
||||
* @type {WeakSet<FixupPluginDefinition>}
|
||||
*/
|
||||
const fixedUpPlugins = new WeakSet();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Determines if two nodes or tokens overlap.
|
||||
* @param {object} first The first node or token to check.
|
||||
* @param {object} second The second node or token to check.
|
||||
* @returns {boolean} True if the two nodes or tokens overlap.
|
||||
*/
|
||||
function nodesOrTokensOverlap(first, second) {
|
||||
return (
|
||||
(first.range[0] <= second.range[0] &&
|
||||
first.range[1] >= second.range[0]) ||
|
||||
(second.range[0] <= first.range[0] && second.range[1] >= first.range[0])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a node is an export declaration.
|
||||
* @param {object} node An AST node.
|
||||
* @returns {boolean} True if the node is an export declaration.
|
||||
*/
|
||||
function looksLikeExport(node) {
|
||||
return (
|
||||
node.type === "ExportDefaultDeclaration" ||
|
||||
node.type === "ExportNamedDeclaration"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for the presence of a JSDoc comment for the given node and returns it.
|
||||
* @param {object} node The AST node to get the comment for.
|
||||
* @param {object} sourceCode A SourceCode instance to get comments.
|
||||
* @returns {object|null} The Block comment token containing the JSDoc comment
|
||||
* for the given node or null if not found.
|
||||
*/
|
||||
function findJSDocComment(node, sourceCode) {
|
||||
const tokenBefore = sourceCode.getTokenBefore(node, {
|
||||
includeComments: true,
|
||||
});
|
||||
|
||||
if (
|
||||
tokenBefore &&
|
||||
tokenBefore.type === "Block" &&
|
||||
tokenBefore.value.charAt(0) === "*" &&
|
||||
node.loc.start.line - tokenBefore.loc.end.line <= 1
|
||||
) {
|
||||
return tokenBefore;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exports
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Takes the given rule and creates a new rule with the `create()` method wrapped
|
||||
* to provide missing methods on the `context` and `sourceCode` objects.
|
||||
* @param {FixupRuleDefinition|FixupLegacyRuleDefinition} ruleDefinition The rule to fix up.
|
||||
* @returns {FixupRuleDefinition} The fixed-up rule.
|
||||
*/
|
||||
function fixupRule(ruleDefinition) {
|
||||
// first check if we've already fixed up this rule
|
||||
if (fixedUpRuleReplacements.has(ruleDefinition)) {
|
||||
return fixedUpRuleReplacements.get(ruleDefinition);
|
||||
}
|
||||
|
||||
const isLegacyRule = typeof ruleDefinition === "function";
|
||||
|
||||
// check to see if this rule definition has already been fixed up
|
||||
if (!isLegacyRule && fixedUpRules.has(ruleDefinition)) {
|
||||
return ruleDefinition;
|
||||
}
|
||||
|
||||
const originalCreate = isLegacyRule
|
||||
? ruleDefinition
|
||||
: ruleDefinition.create.bind(ruleDefinition);
|
||||
|
||||
function ruleCreate(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
// No need to create old methods for ESLint < 9
|
||||
if ("getScope" in context) {
|
||||
return originalCreate(context);
|
||||
}
|
||||
|
||||
let eslintVersion = 9;
|
||||
if (!("getCwd" in context)) {
|
||||
eslintVersion = 10;
|
||||
}
|
||||
|
||||
let compatSourceCode = sourceCode;
|
||||
if (eslintVersion >= 10) {
|
||||
compatSourceCode = Object.assign(Object.create(sourceCode), {
|
||||
getTokenOrCommentBefore(node, skip) {
|
||||
return sourceCode.getTokenBefore(node, {
|
||||
includeComments: true,
|
||||
skip,
|
||||
});
|
||||
},
|
||||
getTokenOrCommentAfter(node, skip) {
|
||||
return sourceCode.getTokenAfter(node, {
|
||||
includeComments: true,
|
||||
skip,
|
||||
});
|
||||
},
|
||||
isSpaceBetweenTokens(first, second) {
|
||||
if (nodesOrTokensOverlap(first, second)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const [startingNodeOrToken, endingNodeOrToken] =
|
||||
first.range[1] <= second.range[0]
|
||||
? [first, second]
|
||||
: [second, first];
|
||||
const firstToken =
|
||||
sourceCode.getLastToken(startingNodeOrToken) ||
|
||||
startingNodeOrToken;
|
||||
const finalToken =
|
||||
sourceCode.getFirstToken(endingNodeOrToken) ||
|
||||
endingNodeOrToken;
|
||||
let currentToken = firstToken;
|
||||
|
||||
while (currentToken !== finalToken) {
|
||||
const nextToken = sourceCode.getTokenAfter(
|
||||
currentToken,
|
||||
{
|
||||
includeComments: true,
|
||||
},
|
||||
);
|
||||
|
||||
if (
|
||||
currentToken.range[1] !== nextToken.range[0] ||
|
||||
(nextToken !== finalToken &&
|
||||
nextToken.type === "JSXText" &&
|
||||
/\s/u.test(nextToken.value))
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
currentToken = nextToken;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
getJSDocComment(node) {
|
||||
let parent = node.parent;
|
||||
|
||||
switch (node.type) {
|
||||
case "ClassDeclaration":
|
||||
case "FunctionDeclaration":
|
||||
return findJSDocComment(
|
||||
looksLikeExport(parent) ? parent : node,
|
||||
sourceCode,
|
||||
);
|
||||
|
||||
case "ClassExpression":
|
||||
return findJSDocComment(parent.parent, sourceCode);
|
||||
|
||||
case "ArrowFunctionExpression":
|
||||
case "FunctionExpression":
|
||||
if (
|
||||
parent.type !== "CallExpression" &&
|
||||
parent.type !== "NewExpression"
|
||||
) {
|
||||
while (
|
||||
!sourceCode.getCommentsBefore(parent)
|
||||
.length &&
|
||||
!/Function/u.test(parent.type) &&
|
||||
parent.type !== "MethodDefinition" &&
|
||||
parent.type !== "Property"
|
||||
) {
|
||||
parent = parent.parent;
|
||||
|
||||
if (!parent) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
parent &&
|
||||
parent.type !== "FunctionDeclaration" &&
|
||||
parent.type !== "Program"
|
||||
) {
|
||||
return findJSDocComment(parent, sourceCode);
|
||||
}
|
||||
}
|
||||
|
||||
return findJSDocComment(node, sourceCode);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Object.freeze(compatSourceCode);
|
||||
}
|
||||
|
||||
let currentNode = compatSourceCode.ast;
|
||||
|
||||
const compatContext = Object.assign(Object.create(context), {
|
||||
parserServices: compatSourceCode.parserServices,
|
||||
|
||||
/*
|
||||
* The following methods rely on the current node in the traversal,
|
||||
* so we need to add them manually.
|
||||
*/
|
||||
getScope() {
|
||||
return compatSourceCode.getScope(currentNode);
|
||||
},
|
||||
|
||||
getAncestors() {
|
||||
return compatSourceCode.getAncestors(currentNode);
|
||||
},
|
||||
|
||||
markVariableAsUsed(variable) {
|
||||
compatSourceCode.markVariableAsUsed(variable, currentNode);
|
||||
},
|
||||
});
|
||||
|
||||
if (eslintVersion >= 10) {
|
||||
Object.assign(compatContext, {
|
||||
parserOptions: compatContext.languageOptions.parserOptions,
|
||||
|
||||
getCwd() {
|
||||
return compatContext.cwd;
|
||||
},
|
||||
|
||||
getFilename() {
|
||||
return compatContext.filename;
|
||||
},
|
||||
|
||||
getPhysicalFilename() {
|
||||
return compatContext.physicalFilename;
|
||||
},
|
||||
|
||||
getSourceCode() {
|
||||
return compatSourceCode;
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(compatContext, "sourceCode", {
|
||||
enumerable: true,
|
||||
value: compatSourceCode,
|
||||
});
|
||||
}
|
||||
|
||||
// add passthrough methods
|
||||
for (const [
|
||||
contextMethodName,
|
||||
sourceCodeMethodName,
|
||||
] of removedMethodNames) {
|
||||
compatContext[contextMethodName] =
|
||||
compatSourceCode[sourceCodeMethodName].bind(compatSourceCode);
|
||||
}
|
||||
|
||||
// freeze just like the original context
|
||||
Object.freeze(compatContext);
|
||||
|
||||
/*
|
||||
* Create the visitor object using the original create() method.
|
||||
* This is necessary to ensure that the visitor object is created
|
||||
* with the correct context.
|
||||
*/
|
||||
const visitor = originalCreate(compatContext);
|
||||
|
||||
/*
|
||||
* Wrap each method in the visitor object to update the currentNode
|
||||
* before calling the original method. This is necessary because the
|
||||
* methods like `getScope()` need to know the current node.
|
||||
*/
|
||||
for (const [methodName, method] of Object.entries(visitor)) {
|
||||
/*
|
||||
* Node is the second argument to most code path methods,
|
||||
* and the third argument for onCodePathSegmentLoop.
|
||||
*/
|
||||
if (methodName.startsWith("on")) {
|
||||
// eslint-disable-next-line no-loop-func -- intentionally updating shared `currentNode` variable
|
||||
visitor[methodName] = (...args) => {
|
||||
currentNode =
|
||||
args[methodName === "onCodePathSegmentLoop" ? 2 : 1];
|
||||
|
||||
return method.call(visitor, ...args);
|
||||
};
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-loop-func -- intentionally updating shared `currentNode` variable
|
||||
visitor[methodName] = (...args) => {
|
||||
currentNode = args[0];
|
||||
|
||||
return method.call(visitor, ...args);
|
||||
};
|
||||
}
|
||||
|
||||
return visitor;
|
||||
}
|
||||
|
||||
const newRuleDefinition = {
|
||||
...(isLegacyRule ? undefined : ruleDefinition),
|
||||
create: ruleCreate,
|
||||
};
|
||||
|
||||
// copy `schema` property of function-style rule or top-level `schema` property of object-style rule into `meta` object
|
||||
// @ts-ignore -- top-level `schema` property was not officially supported for object-style rules so it doesn't exist in types
|
||||
const { schema } = ruleDefinition;
|
||||
if (schema) {
|
||||
if (!newRuleDefinition.meta) {
|
||||
newRuleDefinition.meta = { schema };
|
||||
} else {
|
||||
newRuleDefinition.meta = {
|
||||
...newRuleDefinition.meta,
|
||||
// top-level `schema` had precedence over `meta.schema` so it's okay to overwrite `meta.schema` if it exists
|
||||
schema,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// cache the fixed up rule
|
||||
fixedUpRuleReplacements.set(ruleDefinition, newRuleDefinition);
|
||||
fixedUpRules.add(newRuleDefinition);
|
||||
|
||||
return newRuleDefinition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes the given plugin and creates a new plugin with all of the rules wrapped
|
||||
* to provide missing methods on the `context` and `sourceCode` objects.
|
||||
* @param {FixupPluginDefinition} plugin The plugin to fix up.
|
||||
* @returns {FixupPluginDefinition} The fixed-up plugin.
|
||||
*/
|
||||
function fixupPluginRules(plugin) {
|
||||
// first check if we've already fixed up this plugin
|
||||
if (fixedUpPluginReplacements.has(plugin)) {
|
||||
return fixedUpPluginReplacements.get(plugin);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the plugin has already been fixed up, or if the plugin
|
||||
* doesn't have any rules, we can just return it.
|
||||
*/
|
||||
if (fixedUpPlugins.has(plugin) || !plugin.rules) {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
const newPlugin = {
|
||||
...plugin,
|
||||
rules: Object.fromEntries(
|
||||
Object.entries(plugin.rules).map(([ruleId, ruleDefinition]) => [
|
||||
ruleId,
|
||||
fixupRule(ruleDefinition),
|
||||
]),
|
||||
),
|
||||
};
|
||||
|
||||
// cache the fixed up plugin
|
||||
fixedUpPluginReplacements.set(plugin, newPlugin);
|
||||
fixedUpPlugins.add(newPlugin);
|
||||
|
||||
return newPlugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes the given configuration and creates a new configuration with all of the
|
||||
* rules wrapped to provide missing methods on the `context` and `sourceCode` objects.
|
||||
* @param {FixupConfigArray|FixupConfig} config The configuration to fix up.
|
||||
* @returns {FixupConfigArray} The fixed-up configuration.
|
||||
*/
|
||||
function fixupConfigRules(config) {
|
||||
const configs = Array.isArray(config) ? config : [config];
|
||||
|
||||
return configs.map(configItem => {
|
||||
if (!configItem.plugins) {
|
||||
return configItem;
|
||||
}
|
||||
|
||||
const newPlugins = Object.fromEntries(
|
||||
Object.entries(configItem.plugins).map(([pluginName, plugin]) => [
|
||||
pluginName,
|
||||
fixupPluginRules(plugin),
|
||||
]),
|
||||
);
|
||||
|
||||
return {
|
||||
...configItem,
|
||||
plugins: newPlugins,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @fileoverview Ignore file utilities for the compat package.
|
||||
* @author Nicholas C. Zakas
|
||||
*/
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Types
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** @typedef {import("@eslint/core").ConfigObject} FlatConfig */
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exports
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Converts an ESLint ignore pattern to a minimatch pattern.
|
||||
* @param {string} pattern The .eslintignore or .gitignore pattern to convert.
|
||||
* @returns {string} The converted pattern.
|
||||
*/
|
||||
function convertIgnorePatternToMinimatch(pattern) {
|
||||
const isNegated = pattern.startsWith("!");
|
||||
const negatedPrefix = isNegated ? "!" : "";
|
||||
const patternToTest = (isNegated ? pattern.slice(1) : pattern).trimEnd();
|
||||
|
||||
// special cases
|
||||
if (["", "**", "/**", "**/"].includes(patternToTest)) {
|
||||
return `${negatedPrefix}${patternToTest}`;
|
||||
}
|
||||
|
||||
const firstIndexOfSlash = patternToTest.indexOf("/");
|
||||
|
||||
const matchEverywherePrefix =
|
||||
firstIndexOfSlash < 0 || firstIndexOfSlash === patternToTest.length - 1
|
||||
? "**/"
|
||||
: "";
|
||||
|
||||
const patternWithoutLeadingSlash =
|
||||
firstIndexOfSlash === 0 ? patternToTest.slice(1) : patternToTest;
|
||||
|
||||
/*
|
||||
* Escape `{` and `(` because in gitignore patterns they are just
|
||||
* literal characters without any specific syntactic meaning,
|
||||
* while in minimatch patterns they can form brace expansion or extglob syntax.
|
||||
*
|
||||
* For example, gitignore pattern `src/{a,b}.js` ignores file `src/{a,b}.js`.
|
||||
* But, the same minimatch pattern `src/{a,b}.js` ignores files `src/a.js` and `src/b.js`.
|
||||
* Minimatch pattern `src/\{a,b}.js` is equivalent to gitignore pattern `src/{a,b}.js`.
|
||||
*/
|
||||
const escapedPatternWithoutLeadingSlash =
|
||||
patternWithoutLeadingSlash.replaceAll(
|
||||
// eslint-disable-next-line regexp/no-empty-lookarounds-assertion -- False positive
|
||||
/(?=((?:\\.|[^{(])*))\1([{(])/guy,
|
||||
"$1\\$2",
|
||||
);
|
||||
|
||||
const matchInsideSuffix = patternToTest.endsWith("/**") ? "/*" : "";
|
||||
|
||||
return `${negatedPrefix}${matchEverywherePrefix}${escapedPatternWithoutLeadingSlash}${matchInsideSuffix}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an ignore file and returns an object with the ignore patterns.
|
||||
* @param {string} ignoreFilePath The absolute path to the ignore file.
|
||||
* @param {string} [name] The name of the ignore file config.
|
||||
* @returns {FlatConfig} An object with an `ignores` property that is an array of ignore patterns.
|
||||
* @throws {Error} If the ignore file path is not an absolute path.
|
||||
*/
|
||||
function includeIgnoreFile(ignoreFilePath, name) {
|
||||
if (!path.isAbsolute(ignoreFilePath)) {
|
||||
throw new Error("The ignore file location must be an absolute path.");
|
||||
}
|
||||
|
||||
const ignoreFile = fs.readFileSync(ignoreFilePath, "utf8");
|
||||
const lines = ignoreFile.split(/\r?\n/u);
|
||||
|
||||
return {
|
||||
name: name || "Imported .gitignore patterns",
|
||||
ignores: lines
|
||||
.map(line => line.trim())
|
||||
.filter(line => line && !line.startsWith("#"))
|
||||
.map(convertIgnorePatternToMinimatch),
|
||||
};
|
||||
}
|
||||
|
||||
export { convertIgnorePatternToMinimatch, fixupConfigRules, fixupPluginRules, fixupRule, includeIgnoreFile };
|
||||
+201
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
# ESLint Core
|
||||
|
||||
## Overview
|
||||
|
||||
This package is the future home of the rewritten, runtime-agnostic ESLint core.
|
||||
|
||||
Right now, it exports the core types necessary to implement language plugins.
|
||||
|
||||
## License
|
||||
|
||||
Apache 2.0
|
||||
|
||||
<!-- NOTE: This section is autogenerated. Do not manually edit.-->
|
||||
<!--sponsorsstart-->
|
||||
|
||||
## Sponsors
|
||||
|
||||
The following companies, organizations, and individuals support ESLint's ongoing maintenance and development. [Become a Sponsor](https://eslint.org/donate)
|
||||
to get your logo on our READMEs and [website](https://eslint.org/sponsors).
|
||||
|
||||
<h3>Platinum Sponsors</h3>
|
||||
<p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="128"></a></p><h3>Gold Sponsors</h3>
|
||||
<p><a href="https://qlty.sh/"><img src="https://images.opencollective.com/qltysh/33d157d/logo.png" alt="Qlty Software" height="96"></a></p><h3>Silver Sponsors</h3>
|
||||
<p><a href="https://vite.dev/"><img src="https://images.opencollective.com/vite/d472863/logo.png" alt="Vite" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/2d6c3b6/logo.png" alt="Liftoff" height="64"></a> <a href="https://stackblitz.com"><img src="https://avatars.githubusercontent.com/u/28635252" alt="StackBlitz" height="64"></a></p><h3>Bronze Sponsors</h3>
|
||||
<p><a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://opensource.sap.com"><img src="https://avatars.githubusercontent.com/u/2531208" alt="SAP" height="32"></a> <a href="https://www.crawljobs.com/"><img src="https://images.opencollective.com/crawljobs-poland/fa43a17/logo.png" alt="CrawlJobs" height="32"></a> <a href="#"><img src="https://images.opencollective.com/aeriusventilations-org/avatar.png" alt="aeriusventilation's Org" height="32"></a> <a href="https://depot.dev"><img src="https://images.opencollective.com/depot/39125a1/logo.png" alt="Depot" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340" alt="GitBook" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774" alt="HeroCoders" height="32"></a> <a href="https://www.lambdatest.com"><img src="https://avatars.githubusercontent.com/u/171592363" alt="TestMu AI Open Source Office (Formerly LambdaTest)" height="32"></a></p>
|
||||
<h3>Technology Sponsors</h3>
|
||||
Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.
|
||||
<p><a href="https://netlify.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/netlify-icon.svg" alt="Netlify" height="32"></a> <a href="https://algolia.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/algolia-icon.svg" alt="Algolia" height="32"></a> <a href="https://1password.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/1password-icon.svg" alt="1Password" height="32"></a></p>
|
||||
<!--sponsorsend-->
|
||||
Generated
Vendored
+1159
File diff suppressed because it is too large
Load Diff
Generated
Vendored
+1159
File diff suppressed because it is too large
Load Diff
+52
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"name": "@eslint/core",
|
||||
"version": "1.2.1",
|
||||
"description": "Runtime-agnostic core of ESLint",
|
||||
"type": "module",
|
||||
"types": "./dist/esm/types.d.ts",
|
||||
"exports": {
|
||||
"types": {
|
||||
"import": "./dist/esm/types.d.ts",
|
||||
"require": "./dist/cjs/types.d.cts"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"scripts": {
|
||||
"build:cts": "node -e \"fs.cpSync('dist/esm/types.d.ts', 'dist/cjs/types.d.cts')\"",
|
||||
"build": "tsc && npm run build:cts",
|
||||
"lint:types": "attw --pack",
|
||||
"pretest": "npm run build",
|
||||
"test": "npm run test:types",
|
||||
"test:jsr": "npx -y jsr@latest publish --dry-run",
|
||||
"test:types": "tsc -p tests/types/tsconfig.json"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/eslint/rewrite.git",
|
||||
"directory": "packages/core"
|
||||
},
|
||||
"keywords": [
|
||||
"eslint",
|
||||
"core"
|
||||
],
|
||||
"author": "Nicholas C. Zakas",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/eslint/rewrite/issues"
|
||||
},
|
||||
"homepage": "https://github.com/eslint/rewrite/tree/main/packages/core#readme",
|
||||
"dependencies": {
|
||||
"@types/json-schema": "^7.0.15"
|
||||
},
|
||||
"devDependencies": {
|
||||
"json-schema": "^0.4.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.19.0 || ^22.13.0 || >=24"
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"name": "@eslint/compat",
|
||||
"version": "2.0.5",
|
||||
"description": "Compatibility utilities for ESLint",
|
||||
"type": "module",
|
||||
"main": "dist/esm/index.js",
|
||||
"types": "dist/esm/index.d.ts",
|
||||
"exports": {
|
||||
"require": {
|
||||
"types": "./dist/cjs/index.d.cts",
|
||||
"default": "./dist/cjs/index.cjs"
|
||||
},
|
||||
"import": {
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.js"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"directories": {
|
||||
"test": "tests"
|
||||
},
|
||||
"scripts": {
|
||||
"build:cts": "node ../../tools/build-cts.js dist/esm/index.d.ts dist/cjs/index.d.cts",
|
||||
"build": "rollup -c && tsc -p tsconfig.esm.json && npm run build:cts",
|
||||
"lint:types": "attw --pack",
|
||||
"pretest": "npm run build",
|
||||
"test": "npm run test:unit",
|
||||
"test:coverage": "c8 npm run test:unit",
|
||||
"test:jsr": "npx -y jsr@latest publish --dry-run",
|
||||
"test:unit": "mocha \"tests/**/*.test.js\""
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/eslint/rewrite.git",
|
||||
"directory": "packages/compat"
|
||||
},
|
||||
"keywords": [
|
||||
"eslint",
|
||||
"compatibility",
|
||||
"eslintplugin",
|
||||
"eslint-plugin"
|
||||
],
|
||||
"author": "Nicholas C. Zakas",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/eslint/rewrite/issues"
|
||||
},
|
||||
"homepage": "https://github.com/eslint/rewrite/tree/main/packages/compat#readme",
|
||||
"dependencies": {
|
||||
"@eslint/core": "^1.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^24.7.2",
|
||||
"eslint": "^10.0.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^8.40 || 9 || 10"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"eslint": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.19.0 || ^22.13.0 || >=24"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user