update
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -0,0 +1,199 @@
|
||||
/**
|
||||
* @fileoverview Rule Validator
|
||||
* @author Nicholas C. Zakas
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const ajvImport = require("../shared/ajv");
|
||||
const ajv = ajvImport();
|
||||
const {
|
||||
parseRuleId,
|
||||
getRuleFromConfig,
|
||||
getRuleOptionsSchema,
|
||||
} = require("./flat-config-helpers");
|
||||
const ruleReplacements = require("../../conf/replacements.json");
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Throws a helpful error when a rule cannot be found.
|
||||
* @param {Object} ruleId The rule identifier.
|
||||
* @param {string} ruleId.pluginName The ID of the rule to find.
|
||||
* @param {string} ruleId.ruleName The ID of the rule to find.
|
||||
* @param {Object} config The config to search in.
|
||||
* @throws {TypeError} For missing plugin or rule.
|
||||
* @returns {void}
|
||||
*/
|
||||
function throwRuleNotFoundError({ pluginName, ruleName }, config) {
|
||||
const ruleId = pluginName === "@" ? ruleName : `${pluginName}/${ruleName}`;
|
||||
|
||||
const errorMessageHeader = `Key "rules": Key "${ruleId}"`;
|
||||
|
||||
let errorMessage = `${errorMessageHeader}: Could not find plugin "${pluginName}" in configuration.`;
|
||||
|
||||
const missingPluginErrorMessage = errorMessage;
|
||||
|
||||
// if the plugin exists then we need to check if the rule exists
|
||||
if (config.plugins && config.plugins[pluginName]) {
|
||||
const replacementRuleName = ruleReplacements.rules[ruleName];
|
||||
|
||||
if (pluginName === "@" && replacementRuleName) {
|
||||
errorMessage = `${errorMessageHeader}: Rule "${ruleName}" was removed and replaced by "${replacementRuleName}".`;
|
||||
} else {
|
||||
errorMessage = `${errorMessageHeader}: Could not find "${ruleName}" in plugin "${pluginName}".`;
|
||||
|
||||
// otherwise, let's see if we can find the rule name elsewhere
|
||||
for (const [otherPluginName, otherPlugin] of Object.entries(
|
||||
config.plugins,
|
||||
)) {
|
||||
if (otherPlugin.rules && otherPlugin.rules[ruleName]) {
|
||||
errorMessage += ` Did you mean "${otherPluginName}/${ruleName}"?`;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// falls through to throw error
|
||||
}
|
||||
|
||||
const error = new TypeError(errorMessage);
|
||||
|
||||
if (errorMessage === missingPluginErrorMessage) {
|
||||
error.messageTemplate = "config-plugin-missing";
|
||||
error.messageData = { pluginName, ruleId };
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
/**
|
||||
* The error type when a rule has an invalid `meta.schema`.
|
||||
*/
|
||||
class InvalidRuleOptionsSchemaError extends Error {
|
||||
/**
|
||||
* Creates a new instance.
|
||||
* @param {string} ruleId Id of the rule that has an invalid `meta.schema`.
|
||||
* @param {Error} processingError Error caught while processing the `meta.schema`.
|
||||
*/
|
||||
constructor(ruleId, processingError) {
|
||||
super(
|
||||
`Error while processing options validation schema of rule '${ruleId}': ${processingError.message}`,
|
||||
{ cause: processingError },
|
||||
);
|
||||
this.code = "ESLINT_INVALID_RULE_OPTIONS_SCHEMA";
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exports
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Implements validation functionality for the rules portion of a config.
|
||||
*/
|
||||
class RuleValidator {
|
||||
/**
|
||||
* Creates a new instance.
|
||||
*/
|
||||
constructor() {
|
||||
/**
|
||||
* A collection of compiled validators for rules that have already
|
||||
* been validated.
|
||||
* @type {WeakMap}
|
||||
*/
|
||||
this.validators = new WeakMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates all of the rule configurations in a config against each
|
||||
* rule's schema.
|
||||
* @param {Object} config The full config to validate. This object must
|
||||
* contain both the rules section and the plugins section.
|
||||
* @returns {void}
|
||||
* @throws {Error} If a rule's configuration does not match its schema.
|
||||
*/
|
||||
validate(config) {
|
||||
if (!config.rules) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const [ruleId, ruleOptions] of Object.entries(config.rules)) {
|
||||
// check for edge case
|
||||
if (ruleId === "__proto__") {
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* If a rule is disabled, we don't do any validation. This allows
|
||||
* users to safely set any value to 0 or "off" without worrying
|
||||
* that it will cause a validation error.
|
||||
*
|
||||
* Note: ruleOptions is always an array at this point because
|
||||
* this validation occurs after FlatConfigArray has merged and
|
||||
* normalized values.
|
||||
*/
|
||||
if (ruleOptions[0] === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const rule = getRuleFromConfig(ruleId, config);
|
||||
|
||||
if (!rule) {
|
||||
throwRuleNotFoundError(parseRuleId(ruleId), config);
|
||||
}
|
||||
|
||||
// Precompile and cache validator the first time
|
||||
if (!this.validators.has(rule)) {
|
||||
try {
|
||||
const schema = getRuleOptionsSchema(rule);
|
||||
|
||||
if (schema) {
|
||||
this.validators.set(rule, ajv.compile(schema));
|
||||
}
|
||||
} catch (err) {
|
||||
throw new InvalidRuleOptionsSchemaError(ruleId, err);
|
||||
}
|
||||
}
|
||||
|
||||
const validateRule = this.validators.get(rule);
|
||||
|
||||
if (validateRule) {
|
||||
validateRule(ruleOptions.slice(1));
|
||||
|
||||
if (validateRule.errors) {
|
||||
throw new Error(
|
||||
`Key "rules": Key "${ruleId}":\n${validateRule.errors
|
||||
.map(error => {
|
||||
if (
|
||||
error.keyword === "additionalProperties" &&
|
||||
error.schema === false &&
|
||||
typeof error.parentSchema?.properties ===
|
||||
"object" &&
|
||||
typeof error.params?.additionalProperty ===
|
||||
"string"
|
||||
) {
|
||||
const expectedProperties = Object.keys(
|
||||
error.parentSchema.properties,
|
||||
).map(property => `"${property}"`);
|
||||
|
||||
return `\tValue ${JSON.stringify(error.data)} ${error.message}.\n\t\tUnexpected property "${error.params.additionalProperty}". Expected properties: ${expectedProperties.join(", ")}.\n`;
|
||||
}
|
||||
|
||||
return `\tValue ${JSON.stringify(error.data)} ${error.message}.\n`;
|
||||
})
|
||||
.join("")}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.RuleValidator = RuleValidator;
|
||||
@@ -0,0 +1,3 @@
|
||||
const compare = require('./compare')
|
||||
const eq = (a, b, loose) => compare(a, b, loose) === 0
|
||||
module.exports = eq
|
||||
@@ -0,0 +1,207 @@
|
||||
/* Copyright 2015 Mozilla Foundation
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
import invariant from 'tiny-invariant';
|
||||
|
||||
import type { PDFDocumentProxy } from 'pdfjs-dist';
|
||||
import type {
|
||||
Dest,
|
||||
ResolvedDest,
|
||||
ExternalLinkRel,
|
||||
ExternalLinkTarget,
|
||||
ScrollPageIntoViewArgs,
|
||||
} from './shared/types.js';
|
||||
|
||||
import type { IPDFLinkService } from 'pdfjs-dist/types/web/interfaces.js';
|
||||
|
||||
const DEFAULT_LINK_REL = 'noopener noreferrer nofollow';
|
||||
|
||||
type PDFViewer = {
|
||||
currentPageNumber?: number;
|
||||
scrollPageIntoView: (args: ScrollPageIntoViewArgs) => void;
|
||||
};
|
||||
|
||||
export default class LinkService implements IPDFLinkService {
|
||||
externalLinkEnabled: boolean;
|
||||
externalLinkRel?: ExternalLinkRel;
|
||||
externalLinkTarget?: ExternalLinkTarget;
|
||||
isInPresentationMode: boolean;
|
||||
pdfDocument?: PDFDocumentProxy | null;
|
||||
pdfViewer?: PDFViewer | null;
|
||||
|
||||
constructor() {
|
||||
this.externalLinkEnabled = true;
|
||||
this.externalLinkRel = undefined;
|
||||
this.externalLinkTarget = undefined;
|
||||
this.isInPresentationMode = false;
|
||||
this.pdfDocument = undefined;
|
||||
this.pdfViewer = undefined;
|
||||
}
|
||||
|
||||
setDocument(pdfDocument: PDFDocumentProxy): void {
|
||||
this.pdfDocument = pdfDocument;
|
||||
}
|
||||
|
||||
setViewer(pdfViewer: PDFViewer): void {
|
||||
this.pdfViewer = pdfViewer;
|
||||
}
|
||||
|
||||
setExternalLinkRel(externalLinkRel?: ExternalLinkRel): void {
|
||||
this.externalLinkRel = externalLinkRel;
|
||||
}
|
||||
|
||||
setExternalLinkTarget(externalLinkTarget?: ExternalLinkTarget): void {
|
||||
this.externalLinkTarget = externalLinkTarget;
|
||||
}
|
||||
|
||||
setHistory(): void {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
get pagesCount(): number {
|
||||
return this.pdfDocument ? this.pdfDocument.numPages : 0;
|
||||
}
|
||||
|
||||
get page(): number {
|
||||
invariant(this.pdfViewer, 'PDF viewer is not initialized.');
|
||||
|
||||
return this.pdfViewer.currentPageNumber || 0;
|
||||
}
|
||||
|
||||
set page(value: number) {
|
||||
invariant(this.pdfViewer, 'PDF viewer is not initialized.');
|
||||
|
||||
this.pdfViewer.currentPageNumber = value;
|
||||
}
|
||||
|
||||
get rotation(): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
set rotation(_value) {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
goToDestination(dest: Dest): Promise<void> {
|
||||
return new Promise<ResolvedDest | null>((resolve) => {
|
||||
invariant(this.pdfDocument, 'PDF document not loaded.');
|
||||
|
||||
invariant(dest, 'Destination is not specified.');
|
||||
|
||||
if (typeof dest === 'string') {
|
||||
this.pdfDocument.getDestination(dest).then(resolve);
|
||||
} else if (Array.isArray(dest)) {
|
||||
resolve(dest);
|
||||
} else {
|
||||
dest.then(resolve);
|
||||
}
|
||||
}).then((explicitDest) => {
|
||||
invariant(Array.isArray(explicitDest), `"${explicitDest}" is not a valid destination array.`);
|
||||
|
||||
const destRef = explicitDest[0];
|
||||
|
||||
new Promise<number>((resolve) => {
|
||||
invariant(this.pdfDocument, 'PDF document not loaded.');
|
||||
|
||||
if (destRef instanceof Object) {
|
||||
this.pdfDocument
|
||||
.getPageIndex(destRef)
|
||||
.then((pageIndex) => {
|
||||
resolve(pageIndex);
|
||||
})
|
||||
.catch(() => {
|
||||
invariant(false, `"${destRef}" is not a valid page reference.`);
|
||||
});
|
||||
} else if (typeof destRef === 'number') {
|
||||
resolve(destRef);
|
||||
} else {
|
||||
invariant(false, `"${destRef}" is not a valid destination reference.`);
|
||||
}
|
||||
}).then((pageIndex) => {
|
||||
const pageNumber = pageIndex + 1;
|
||||
|
||||
invariant(this.pdfViewer, 'PDF viewer is not initialized.');
|
||||
|
||||
invariant(
|
||||
pageNumber >= 1 && pageNumber <= this.pagesCount,
|
||||
`"${pageNumber}" is not a valid page number.`,
|
||||
);
|
||||
|
||||
this.pdfViewer.scrollPageIntoView({
|
||||
dest: explicitDest,
|
||||
pageIndex,
|
||||
pageNumber,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
navigateTo(dest: Dest): void {
|
||||
this.goToDestination(dest);
|
||||
}
|
||||
|
||||
goToPage(pageNumber: number): void {
|
||||
const pageIndex = pageNumber - 1;
|
||||
|
||||
invariant(this.pdfViewer, 'PDF viewer is not initialized.');
|
||||
|
||||
invariant(
|
||||
pageNumber >= 1 && pageNumber <= this.pagesCount,
|
||||
`"${pageNumber}" is not a valid page number.`,
|
||||
);
|
||||
|
||||
this.pdfViewer.scrollPageIntoView({
|
||||
pageIndex,
|
||||
pageNumber,
|
||||
});
|
||||
}
|
||||
|
||||
addLinkAttributes(link: HTMLAnchorElement, url: string, newWindow: boolean): void {
|
||||
link.href = url;
|
||||
link.rel = this.externalLinkRel || DEFAULT_LINK_REL;
|
||||
link.target = newWindow ? '_blank' : this.externalLinkTarget || '';
|
||||
}
|
||||
|
||||
getDestinationHash(): string {
|
||||
return '#';
|
||||
}
|
||||
|
||||
getAnchorUrl(): string {
|
||||
return '#';
|
||||
}
|
||||
|
||||
setHash(): void {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
executeNamedAction(): void {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
cachePageRef(): void {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
isPageVisible(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
isPageCached(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
executeSetOCGState(): void {
|
||||
// Intentionally empty
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"name": "punycode",
|
||||
"version": "2.3.1",
|
||||
"description": "A robust Punycode converter that fully complies to RFC 3492 and RFC 5891, and works on nearly all JavaScript platforms.",
|
||||
"homepage": "https://mths.be/punycode",
|
||||
"main": "punycode.js",
|
||||
"jsnext:main": "punycode.es6.js",
|
||||
"module": "punycode.es6.js",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"keywords": [
|
||||
"punycode",
|
||||
"unicode",
|
||||
"idn",
|
||||
"idna",
|
||||
"dns",
|
||||
"url",
|
||||
"domain"
|
||||
],
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
"name": "Mathias Bynens",
|
||||
"url": "https://mathiasbynens.be/"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Mathias Bynens",
|
||||
"url": "https://mathiasbynens.be/"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mathiasbynens/punycode.js.git"
|
||||
},
|
||||
"bugs": "https://github.com/mathiasbynens/punycode.js/issues",
|
||||
"files": [
|
||||
"LICENSE-MIT.txt",
|
||||
"punycode.js",
|
||||
"punycode.es6.js"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "mocha tests",
|
||||
"build": "node scripts/prepublish.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"codecov": "^3.8.3",
|
||||
"nyc": "^15.1.0",
|
||||
"mocha": "^10.2.0"
|
||||
},
|
||||
"jspm": {
|
||||
"map": {
|
||||
"./punycode.js": {
|
||||
"node": "@node/punycode"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* @fileoverview Expose out ESLint and CLI to require.
|
||||
* @author Ian Christian Myers
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const { ESLint, shouldUseFlatConfig } = require("./eslint/eslint");
|
||||
const { LegacyESLint } = require("./eslint/legacy-eslint");
|
||||
const { Linter } = require("./linter");
|
||||
const { RuleTester } = require("./rule-tester");
|
||||
const { SourceCode } = require("./languages/js/source-code");
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Loads the correct ESLint constructor given the options.
|
||||
* @param {Object} [options] The options object
|
||||
* @param {boolean} [options.useFlatConfig] Whether or not to use a flat config
|
||||
* @returns {Promise<ESLint|LegacyESLint>} The ESLint constructor
|
||||
*/
|
||||
async function loadESLint({ useFlatConfig } = {}) {
|
||||
/*
|
||||
* Note: The v8.x version of this function also accepted a `cwd` option, but
|
||||
* it is not used in this implementation so we silently ignore it.
|
||||
*/
|
||||
|
||||
const shouldESLintUseFlatConfig =
|
||||
useFlatConfig ?? (await shouldUseFlatConfig());
|
||||
|
||||
return shouldESLintUseFlatConfig ? ESLint : LegacyESLint;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Exports
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
module.exports = {
|
||||
Linter,
|
||||
loadESLint,
|
||||
ESLint,
|
||||
RuleTester,
|
||||
SourceCode,
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
import { NavigateOptions } from './link.js';
|
||||
import { RoutePaths } from './routeInfo.js';
|
||||
import { AnyRouter, RegisteredRouter } from './router.js';
|
||||
import { PickAsRequired } from './utils.js';
|
||||
export type AnyRedirect = Redirect<any, any, any, any, any>;
|
||||
/**
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType)
|
||||
*/
|
||||
export type Redirect<TRouter extends AnyRouter = RegisteredRouter, TFrom extends RoutePaths<TRouter['routeTree']> | string = '/', TTo extends string | undefined = '.', TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom, TMaskTo extends string = '.'> = {
|
||||
href?: string;
|
||||
/**
|
||||
* @deprecated Use `statusCode` instead
|
||||
**/
|
||||
code?: number;
|
||||
/**
|
||||
* The HTTP status code to use when redirecting.
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#statuscode-property)
|
||||
*/
|
||||
statusCode?: number;
|
||||
/**
|
||||
* If provided, will throw the redirect object instead of returning it. This can be useful in places where `throwing` in a function might cause it to have a return type of `never`. In that case, you can use `redirect({ throw: true })` to throw the redirect object instead of returning it.
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#throw-property)
|
||||
*/
|
||||
throw?: any;
|
||||
/**
|
||||
* The HTTP headers to use when redirecting.
|
||||
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RedirectType#headers-property)
|
||||
*/
|
||||
headers?: HeadersInit;
|
||||
} & NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>;
|
||||
export type ResolvedRedirect<TRouter extends AnyRouter = RegisteredRouter, TFrom extends RoutePaths<TRouter['routeTree']> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouter['routeTree']> = TFrom, TMaskTo extends string = ''> = PickAsRequired<Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>, 'code' | 'statusCode' | 'headers'> & {
|
||||
href: string;
|
||||
};
|
||||
export declare function redirect<TRouter extends RegisteredRouter, const TTo extends string | undefined, const TFrom extends string = string, const TMaskFrom extends string = TFrom, const TMaskTo extends string = ''>(opts: Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): Redirect<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>;
|
||||
export declare function isRedirect(obj: any): obj is AnyRedirect;
|
||||
export declare function isResolvedRedirect(obj: any): obj is ResolvedRedirect;
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
exports.ast = require('./ast');
|
||||
exports.code = require('./code');
|
||||
exports.keyword = require('./keyword');
|
||||
}());
|
||||
/* vim: set sw=4 ts=4 et tw=80 : */
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"Asset.js","sources":["../../src/Asset.tsx"],"sourcesContent":["import type { RouterManagedTag } from '@tanstack/router-core'\n\nexport function Asset({ tag, attrs, children }: RouterManagedTag): any {\n switch (tag) {\n case 'title':\n return (\n <title {...attrs} suppressHydrationWarning>\n {children}\n </title>\n )\n case 'meta':\n return <meta {...attrs} suppressHydrationWarning />\n case 'link':\n return <link {...attrs} suppressHydrationWarning />\n case 'style':\n return (\n <style\n {...attrs}\n dangerouslySetInnerHTML={{ __html: children as any }}\n />\n )\n case 'script':\n if ((attrs as any) && (attrs as any).src) {\n return <script {...attrs} suppressHydrationWarning />\n }\n if (typeof children === 'string')\n return (\n <script\n {...attrs}\n dangerouslySetInnerHTML={{\n __html: children,\n }}\n suppressHydrationWarning\n />\n )\n return null\n default:\n return null\n }\n}\n"],"names":[],"mappings":";AAEO,SAAS,MAAM,EAAE,KAAK,OAAO,YAAmC;AACrE,UAAQ,KAAK;AAAA,IACX,KAAK;AACH,iCACG,SAAO,EAAA,GAAG,OAAO,0BAAwB,MACvC,UACH;AAAA,IAEJ,KAAK;AACH,aAAQ,oBAAA,QAAA,EAAM,GAAG,OAAO,0BAAwB,MAAC;AAAA,IACnD,KAAK;AACH,aAAQ,oBAAA,QAAA,EAAM,GAAG,OAAO,0BAAwB,MAAC;AAAA,IACnD,KAAK;AAED,aAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACE,GAAG;AAAA,UACJ,yBAAyB,EAAE,QAAQ,SAAgB;AAAA,QAAA;AAAA,MACrD;AAAA,IAEJ,KAAK;AACE,UAAA,SAAkB,MAAc,KAAK;AACxC,eAAQ,oBAAA,UAAA,EAAQ,GAAG,OAAO,0BAAwB,MAAC;AAAA,MAAA;AAErD,UAAI,OAAO,aAAa;AAEpB,eAAA;AAAA,UAAC;AAAA,UAAA;AAAA,YACE,GAAG;AAAA,YACJ,yBAAyB;AAAA,cACvB,QAAQ;AAAA,YACV;AAAA,YACA,0BAAwB;AAAA,UAAA;AAAA,QAC1B;AAEG,aAAA;AAAA,IACT;AACS,aAAA;AAAA,EAAA;AAEb;"}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_helperValidatorIdentifier","require","isValidIdentifier","name","reserved","isKeyword","isStrictReservedWord","isIdentifierName"],"sources":["../../src/validators/isValidIdentifier.ts"],"sourcesContent":["import {\n isIdentifierName,\n isStrictReservedWord,\n isKeyword,\n} from \"@babel/helper-validator-identifier\";\n\n/**\n * Check if the input `name` is a valid identifier name\n * and isn't a reserved word.\n */\nexport default function isValidIdentifier(\n name: string,\n reserved: boolean = true,\n): boolean {\n if (typeof name !== \"string\") return false;\n\n if (reserved) {\n // \"await\" is invalid in module, valid in script; better be safe (see #4952)\n if (isKeyword(name) || isStrictReservedWord(name, true)) {\n return false;\n }\n }\n\n return isIdentifierName(name);\n}\n"],"mappings":";;;;;;AAAA,IAAAA,0BAAA,GAAAC,OAAA;AAUe,SAASC,iBAAiBA,CACvCC,IAAY,EACZC,QAAiB,GAAG,IAAI,EACf;EACT,IAAI,OAAOD,IAAI,KAAK,QAAQ,EAAE,OAAO,KAAK;EAE1C,IAAIC,QAAQ,EAAE;IAEZ,IAAI,IAAAC,oCAAS,EAACF,IAAI,CAAC,IAAI,IAAAG,+CAAoB,EAACH,IAAI,EAAE,IAAI,CAAC,EAAE;MACvD,OAAO,KAAK;IACd;EACF;EAEA,OAAO,IAAAI,2CAAgB,EAACJ,IAAI,CAAC;AAC/B","ignoreList":[]}
|
||||
@@ -0,0 +1,24 @@
|
||||
'use strict'
|
||||
|
||||
let Node = require('./node')
|
||||
|
||||
class Declaration extends Node {
|
||||
get variable() {
|
||||
return this.prop.startsWith('--') || this.prop[0] === '$'
|
||||
}
|
||||
|
||||
constructor(defaults) {
|
||||
if (
|
||||
defaults &&
|
||||
typeof defaults.value !== 'undefined' &&
|
||||
typeof defaults.value !== 'string'
|
||||
) {
|
||||
defaults = { ...defaults, value: String(defaults.value) }
|
||||
}
|
||||
super(defaults)
|
||||
this.type = 'decl'
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Declaration
|
||||
Declaration.default = Declaration
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"136":0.30968,_:"2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 137 138 139 140 3.5 3.6"},D:{"118":0.18581,"131":0.8671,"133":1.5484,"134":2.9132,_:"4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 119 120 121 122 123 124 125 126 127 128 129 130 132 135 136 137 138"},F:{_:"9 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 60 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 9.5-9.6 10.0-10.1 10.5 10.6 11.1 11.5 11.6 12.1"},B:{"117":0.06194,"130":0.12387,"131":0.12387,"132":0.30968,"133":1.17678,"134":3.90418,_:"12 13 14 15 16 17 18 79 80 81 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 118 119 120 121 122 123 124 125 126 127 128 129"},E:{_:"0 4 5 6 7 8 9 10 11 12 13 14 15 3.1 3.2 5.1 6.1 7.1 9.1 10.1 11.1 12.1 13.1 14.1 15.1 15.2-15.3 15.4 15.5 15.6 16.0 16.1 16.2 16.3 16.4 16.5 16.6 17.0 17.1 17.2 17.3 17.4 17.6 18.0 18.1 18.2 18.4","17.5":0.18581,"18.3":0.12387},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0.00055,"5.0-5.1":0,"6.0-6.1":0.00166,"7.0-7.1":0.00111,"8.1-8.4":0,"9.0-9.2":0.00083,"9.3":0.00387,"10.0-10.2":0.00028,"10.3":0.00636,"11.0-11.2":0.02931,"11.3-11.4":0.00194,"12.0-12.1":0.00111,"12.2-12.5":0.02737,"13.0-13.1":0.00055,"13.2":0.00083,"13.3":0.00111,"13.4-13.7":0.00387,"14.0-14.4":0.00968,"14.5-14.8":0.01161,"15.0-15.1":0.00636,"15.2-15.3":0.00636,"15.4":0.00774,"15.5":0.00885,"15.6-15.8":0.10893,"16.0":0.01548,"16.1":0.03179,"16.2":0.01659,"16.3":0.02875,"16.4":0.00636,"16.5":0.01189,"16.6-16.7":0.12911,"17.0":0.00774,"17.1":0.01382,"17.2":0.01051,"17.3":0.01465,"17.4":0.02931,"17.5":0.06525,"17.6-17.7":0.18938,"18.0":0.05308,"18.1":0.17363,"18.2":0.07769,"18.3":1.62373,"18.4":0.02405},P:{"21":1.19952,"22":0.06099,"24":0.06099,"25":0.43711,"27":1.13852,_:"4 20 23 26 5.0-5.4 6.2-6.4 7.2-7.4 8.2 9.2 10.1 11.1-11.2 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0"},I:{"0":0.06217,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0.00002,"4.4":0,"4.4.3-4.4.4":0.00007},K:{"0":0.18691,_:"10 11 12 11.1 11.5 12.1"},A:{_:"6 7 8 9 10 11 5.5"},S:{_:"2.5 3.0-3.1"},J:{_:"7 10"},N:{_:"10 11"},R:{_:"0"},M:{_:"0"},Q:{_:"14.9"},O:{_:"0"},H:{"0":0},L:{"0":81.51111}};
|
||||
@@ -0,0 +1,362 @@
|
||||
/**
|
||||
* @fileoverview Rule to require or disallow yoda comparisons
|
||||
* @author Nicholas C. Zakas
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Determines whether an operator is a comparison operator.
|
||||
* @param {string} operator The operator to check.
|
||||
* @returns {boolean} Whether or not it is a comparison operator.
|
||||
*/
|
||||
function isComparisonOperator(operator) {
|
||||
return /^(==|===|!=|!==|<|>|<=|>=)$/u.test(operator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether an operator is an equality operator.
|
||||
* @param {string} operator The operator to check.
|
||||
* @returns {boolean} Whether or not it is an equality operator.
|
||||
*/
|
||||
function isEqualityOperator(operator) {
|
||||
return /^(==|===)$/u.test(operator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether an operator is one used in a range test.
|
||||
* Allowed operators are `<` and `<=`.
|
||||
* @param {string} operator The operator to check.
|
||||
* @returns {boolean} Whether the operator is used in range tests.
|
||||
*/
|
||||
function isRangeTestOperator(operator) {
|
||||
return ["<", "<="].includes(operator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a non-Literal node is a negative number that should be
|
||||
* treated as if it were a single Literal node.
|
||||
* @param {ASTNode} node Node to test.
|
||||
* @returns {boolean} True if the node is a negative number that looks like a
|
||||
* real literal and should be treated as such.
|
||||
*/
|
||||
function isNegativeNumericLiteral(node) {
|
||||
return (
|
||||
node.type === "UnaryExpression" &&
|
||||
node.operator === "-" &&
|
||||
node.prefix &&
|
||||
astUtils.isNumericLiteral(node.argument)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a non-Literal node should be treated as a single Literal node.
|
||||
* @param {ASTNode} node Node to test
|
||||
* @returns {boolean} True if the node should be treated as a single Literal node.
|
||||
*/
|
||||
function looksLikeLiteral(node) {
|
||||
return (
|
||||
isNegativeNumericLiteral(node) || astUtils.isStaticTemplateLiteral(node)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to derive a Literal node from nodes that are treated like literals.
|
||||
* @param {ASTNode} node Node to normalize.
|
||||
* @returns {ASTNode} One of the following options.
|
||||
* 1. The original node if the node is already a Literal
|
||||
* 2. A normalized Literal node with the negative number as the value if the
|
||||
* node represents a negative number literal.
|
||||
* 3. A normalized Literal node with the string as the value if the node is
|
||||
* a Template Literal without expression.
|
||||
* 4. Otherwise `null`.
|
||||
*/
|
||||
function getNormalizedLiteral(node) {
|
||||
if (node.type === "Literal") {
|
||||
return node;
|
||||
}
|
||||
|
||||
if (isNegativeNumericLiteral(node)) {
|
||||
return {
|
||||
type: "Literal",
|
||||
value: -node.argument.value,
|
||||
raw: `-${node.argument.value}`,
|
||||
};
|
||||
}
|
||||
|
||||
if (astUtils.isStaticTemplateLiteral(node)) {
|
||||
return {
|
||||
type: "Literal",
|
||||
value: node.quasis[0].value.cooked,
|
||||
raw: node.quasis[0].value.raw,
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "suggestion",
|
||||
|
||||
defaultOptions: [
|
||||
"never",
|
||||
{
|
||||
exceptRange: false,
|
||||
onlyEquality: false,
|
||||
},
|
||||
],
|
||||
|
||||
docs: {
|
||||
description: 'Require or disallow "Yoda" conditions',
|
||||
recommended: false,
|
||||
frozen: true,
|
||||
url: "https://eslint.org/docs/latest/rules/yoda",
|
||||
},
|
||||
|
||||
schema: [
|
||||
{
|
||||
enum: ["always", "never"],
|
||||
},
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
exceptRange: {
|
||||
type: "boolean",
|
||||
},
|
||||
onlyEquality: {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
|
||||
fixable: "code",
|
||||
messages: {
|
||||
expected:
|
||||
"Expected literal to be on the {{expectedSide}} side of {{operator}}.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const [when, { exceptRange, onlyEquality }] = context.options;
|
||||
const always = when === "always";
|
||||
const sourceCode = context.sourceCode;
|
||||
|
||||
/**
|
||||
* Determines whether node represents a range test.
|
||||
* A range test is a "between" test like `(0 <= x && x < 1)` or an "outside"
|
||||
* test like `(x < 0 || 1 <= x)`. It must be wrapped in parentheses, and
|
||||
* both operators must be `<` or `<=`. Finally, the literal on the left side
|
||||
* must be less than or equal to the literal on the right side so that the
|
||||
* test makes any sense.
|
||||
* @param {ASTNode} node LogicalExpression node to test.
|
||||
* @returns {boolean} Whether node is a range test.
|
||||
*/
|
||||
function isRangeTest(node) {
|
||||
const left = node.left,
|
||||
right = node.right;
|
||||
|
||||
/**
|
||||
* Determines whether node is of the form `0 <= x && x < 1`.
|
||||
* @returns {boolean} Whether node is a "between" range test.
|
||||
*/
|
||||
function isBetweenTest() {
|
||||
if (
|
||||
node.operator === "&&" &&
|
||||
astUtils.isSameReference(left.right, right.left)
|
||||
) {
|
||||
const leftLiteral = getNormalizedLiteral(left.left);
|
||||
const rightLiteral = getNormalizedLiteral(right.right);
|
||||
|
||||
if (leftLiteral === null && rightLiteral === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rightLiteral === null || leftLiteral === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (leftLiteral.value <= rightLiteral.value) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether node is of the form `x < 0 || 1 <= x`.
|
||||
* @returns {boolean} Whether node is an "outside" range test.
|
||||
*/
|
||||
function isOutsideTest() {
|
||||
if (
|
||||
node.operator === "||" &&
|
||||
astUtils.isSameReference(left.left, right.right)
|
||||
) {
|
||||
const leftLiteral = getNormalizedLiteral(left.right);
|
||||
const rightLiteral = getNormalizedLiteral(right.left);
|
||||
|
||||
if (leftLiteral === null && rightLiteral === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rightLiteral === null || leftLiteral === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (leftLiteral.value <= rightLiteral.value) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether node is wrapped in parentheses.
|
||||
* @returns {boolean} Whether node is preceded immediately by an open
|
||||
* paren token and followed immediately by a close
|
||||
* paren token.
|
||||
*/
|
||||
function isParenWrapped() {
|
||||
return astUtils.isParenthesised(sourceCode, node);
|
||||
}
|
||||
|
||||
return (
|
||||
node.type === "LogicalExpression" &&
|
||||
left.type === "BinaryExpression" &&
|
||||
right.type === "BinaryExpression" &&
|
||||
isRangeTestOperator(left.operator) &&
|
||||
isRangeTestOperator(right.operator) &&
|
||||
(isBetweenTest() || isOutsideTest()) &&
|
||||
isParenWrapped()
|
||||
);
|
||||
}
|
||||
|
||||
const OPERATOR_FLIP_MAP = {
|
||||
"===": "===",
|
||||
"!==": "!==",
|
||||
"==": "==",
|
||||
"!=": "!=",
|
||||
"<": ">",
|
||||
">": "<",
|
||||
"<=": ">=",
|
||||
">=": "<=",
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a string representation of a BinaryExpression node with its sides/operator flipped around.
|
||||
* @param {ASTNode} node The BinaryExpression node
|
||||
* @returns {string} A string representation of the node with the sides and operator flipped
|
||||
*/
|
||||
function getFlippedString(node) {
|
||||
const operatorToken = sourceCode.getFirstTokenBetween(
|
||||
node.left,
|
||||
node.right,
|
||||
token => token.value === node.operator,
|
||||
);
|
||||
const lastLeftToken = sourceCode.getTokenBefore(operatorToken);
|
||||
const firstRightToken = sourceCode.getTokenAfter(operatorToken);
|
||||
|
||||
const source = sourceCode.getText();
|
||||
|
||||
const leftText = source.slice(
|
||||
node.range[0],
|
||||
lastLeftToken.range[1],
|
||||
);
|
||||
const textBeforeOperator = source.slice(
|
||||
lastLeftToken.range[1],
|
||||
operatorToken.range[0],
|
||||
);
|
||||
const textAfterOperator = source.slice(
|
||||
operatorToken.range[1],
|
||||
firstRightToken.range[0],
|
||||
);
|
||||
const rightText = source.slice(
|
||||
firstRightToken.range[0],
|
||||
node.range[1],
|
||||
);
|
||||
|
||||
const tokenBefore = sourceCode.getTokenBefore(node);
|
||||
const tokenAfter = sourceCode.getTokenAfter(node);
|
||||
let prefix = "";
|
||||
let suffix = "";
|
||||
|
||||
if (
|
||||
tokenBefore &&
|
||||
tokenBefore.range[1] === node.range[0] &&
|
||||
!astUtils.canTokensBeAdjacent(tokenBefore, firstRightToken)
|
||||
) {
|
||||
prefix = " ";
|
||||
}
|
||||
|
||||
if (
|
||||
tokenAfter &&
|
||||
node.range[1] === tokenAfter.range[0] &&
|
||||
!astUtils.canTokensBeAdjacent(lastLeftToken, tokenAfter)
|
||||
) {
|
||||
suffix = " ";
|
||||
}
|
||||
|
||||
return (
|
||||
prefix +
|
||||
rightText +
|
||||
textBeforeOperator +
|
||||
OPERATOR_FLIP_MAP[operatorToken.value] +
|
||||
textAfterOperator +
|
||||
leftText +
|
||||
suffix
|
||||
);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
return {
|
||||
BinaryExpression(node) {
|
||||
const expectedLiteral = always ? node.left : node.right;
|
||||
const expectedNonLiteral = always ? node.right : node.left;
|
||||
|
||||
// If `expectedLiteral` is not a literal, and `expectedNonLiteral` is a literal, raise an error.
|
||||
if (
|
||||
(expectedNonLiteral.type === "Literal" ||
|
||||
looksLikeLiteral(expectedNonLiteral)) &&
|
||||
!(
|
||||
expectedLiteral.type === "Literal" ||
|
||||
looksLikeLiteral(expectedLiteral)
|
||||
) &&
|
||||
!(!isEqualityOperator(node.operator) && onlyEquality) &&
|
||||
isComparisonOperator(node.operator) &&
|
||||
!(exceptRange && isRangeTest(node.parent))
|
||||
) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "expected",
|
||||
data: {
|
||||
operator: node.operator,
|
||||
expectedSide: always ? "left" : "right",
|
||||
},
|
||||
fix: fixer =>
|
||||
fixer.replaceText(node, getFlippedString(node)),
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user