including-modules
This commit is contained in:
+3
@@ -0,0 +1,3 @@
|
||||
# `@next/env`
|
||||
|
||||
Next.js' util for loading dotenv files in with the proper priorities
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
export type Env = {
|
||||
[key: string]: string | undefined;
|
||||
};
|
||||
export type LoadedEnvFiles = Array<{
|
||||
path: string;
|
||||
contents: string;
|
||||
env: Env;
|
||||
}>;
|
||||
export declare let initialEnv: Env | undefined;
|
||||
export declare function updateInitialEnv(newEnv: Env): void;
|
||||
type Log = {
|
||||
info: (...args: any[]) => void;
|
||||
error: (...args: any[]) => void;
|
||||
};
|
||||
export declare function processEnv(loadedEnvFiles: LoadedEnvFiles, dir?: string, log?: Log, forceReload?: boolean, onReload?: (envFilePath: string) => void): Env[];
|
||||
export declare function resetEnv(): void;
|
||||
export declare function loadEnvConfig(dir: string, dev?: boolean, log?: Log, forceReload?: boolean, onReload?: (envFilePath: string) => void): {
|
||||
combinedEnv: Env;
|
||||
parsedEnv: Env | undefined;
|
||||
loadedEnvFiles: LoadedEnvFiles;
|
||||
};
|
||||
export {};
|
||||
+1
File diff suppressed because one or more lines are too long
+36
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "@next/env",
|
||||
"version": "16.1.6",
|
||||
"keywords": [
|
||||
"react",
|
||||
"next",
|
||||
"next.js",
|
||||
"dotenv"
|
||||
],
|
||||
"description": "Next.js dotenv file loading",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/vercel/next.js",
|
||||
"directory": "packages/next-env"
|
||||
},
|
||||
"author": "Next.js Team <support@vercel.com>",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"dev": "ncc build ./index.ts -w -o dist/",
|
||||
"prebuild:source": "node ../../scripts/rm.mjs dist",
|
||||
"types": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
|
||||
"build:source": "ncc build ./index.ts -o ./dist/ --minify --no-cache --no-source-map-register",
|
||||
"build": "pnpm build:source && pnpm types",
|
||||
"prepublishOnly": "cd ../../ && turbo run build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vercel/ncc": "0.34.0",
|
||||
"dotenv": "16.3.1",
|
||||
"dotenv-expand": "10.0.0"
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
# `@next/eslint-plugin-next`
|
||||
|
||||
Documentation for `@next/eslint-plugin-next` can be found at:
|
||||
https://nextjs.org/docs/app/api-reference/config/eslint
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
import type { Linter, Rule } from 'eslint';
|
||||
declare const plugin: {
|
||||
meta: {
|
||||
name: string;
|
||||
};
|
||||
rules: {
|
||||
'google-font-display': Rule.RuleModule;
|
||||
'google-font-preconnect': Rule.RuleModule;
|
||||
'inline-script-id': Rule.RuleModule;
|
||||
'next-script-for-ga': Rule.RuleModule;
|
||||
'no-assign-module-variable': Rule.RuleModule;
|
||||
'no-async-client-component': Rule.RuleModule;
|
||||
'no-before-interactive-script-outside-document': Rule.RuleModule;
|
||||
'no-css-tags': Rule.RuleModule;
|
||||
'no-document-import-in-page': Rule.RuleModule;
|
||||
'no-duplicate-head': Rule.RuleModule;
|
||||
'no-head-element': Rule.RuleModule;
|
||||
'no-head-import-in-document': Rule.RuleModule;
|
||||
'no-html-link-for-pages': Rule.RuleModule;
|
||||
'no-img-element': Rule.RuleModule;
|
||||
'no-page-custom-font': Rule.RuleModule;
|
||||
'no-script-component-in-head': Rule.RuleModule;
|
||||
'no-styled-jsx-in-document': Rule.RuleModule;
|
||||
'no-sync-scripts': Rule.RuleModule;
|
||||
'no-title-in-document-head': Rule.RuleModule;
|
||||
'no-typos': Rule.RuleModule;
|
||||
'no-unwanted-polyfillio': Rule.RuleModule;
|
||||
};
|
||||
configs: ESLintPluginConfigs;
|
||||
};
|
||||
type ESLintPluginConfigs = {
|
||||
'recommended-legacy': Linter.LegacyConfig;
|
||||
'core-web-vitals-legacy': Linter.LegacyConfig;
|
||||
recommended: Linter.Config;
|
||||
'core-web-vitals': Linter.Config;
|
||||
};
|
||||
export default plugin;
|
||||
export declare const rules: {
|
||||
'google-font-display': Rule.RuleModule;
|
||||
'google-font-preconnect': Rule.RuleModule;
|
||||
'inline-script-id': Rule.RuleModule;
|
||||
'next-script-for-ga': Rule.RuleModule;
|
||||
'no-assign-module-variable': Rule.RuleModule;
|
||||
'no-async-client-component': Rule.RuleModule;
|
||||
'no-before-interactive-script-outside-document': Rule.RuleModule;
|
||||
'no-css-tags': Rule.RuleModule;
|
||||
'no-document-import-in-page': Rule.RuleModule;
|
||||
'no-duplicate-head': Rule.RuleModule;
|
||||
'no-head-element': Rule.RuleModule;
|
||||
'no-head-import-in-document': Rule.RuleModule;
|
||||
'no-html-link-for-pages': Rule.RuleModule;
|
||||
'no-img-element': Rule.RuleModule;
|
||||
'no-page-custom-font': Rule.RuleModule;
|
||||
'no-script-component-in-head': Rule.RuleModule;
|
||||
'no-styled-jsx-in-document': Rule.RuleModule;
|
||||
'no-sync-scripts': Rule.RuleModule;
|
||||
'no-title-in-document-head': Rule.RuleModule;
|
||||
'no-typos': Rule.RuleModule;
|
||||
'no-unwanted-polyfillio': Rule.RuleModule;
|
||||
}, configs: ESLintPluginConfigs;
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
function _export(target, all) {
|
||||
for(var name in all)Object.defineProperty(target, name, {
|
||||
enumerable: true,
|
||||
get: all[name]
|
||||
});
|
||||
}
|
||||
_export(exports, {
|
||||
configs: function() {
|
||||
return configs;
|
||||
},
|
||||
default: function() {
|
||||
return _default;
|
||||
},
|
||||
rules: function() {
|
||||
return rules;
|
||||
}
|
||||
});
|
||||
var _googlefontdisplay = /*#__PURE__*/ _interop_require_default(require("./rules/google-font-display"));
|
||||
var _googlefontpreconnect = /*#__PURE__*/ _interop_require_default(require("./rules/google-font-preconnect"));
|
||||
var _inlinescriptid = /*#__PURE__*/ _interop_require_default(require("./rules/inline-script-id"));
|
||||
var _nextscriptforga = /*#__PURE__*/ _interop_require_default(require("./rules/next-script-for-ga"));
|
||||
var _noassignmodulevariable = /*#__PURE__*/ _interop_require_default(require("./rules/no-assign-module-variable"));
|
||||
var _noasyncclientcomponent = /*#__PURE__*/ _interop_require_default(require("./rules/no-async-client-component"));
|
||||
var _nobeforeinteractivescriptoutsidedocument = /*#__PURE__*/ _interop_require_default(require("./rules/no-before-interactive-script-outside-document"));
|
||||
var _nocsstags = /*#__PURE__*/ _interop_require_default(require("./rules/no-css-tags"));
|
||||
var _nodocumentimportinpage = /*#__PURE__*/ _interop_require_default(require("./rules/no-document-import-in-page"));
|
||||
var _noduplicatehead = /*#__PURE__*/ _interop_require_default(require("./rules/no-duplicate-head"));
|
||||
var _noheadelement = /*#__PURE__*/ _interop_require_default(require("./rules/no-head-element"));
|
||||
var _noheadimportindocument = /*#__PURE__*/ _interop_require_default(require("./rules/no-head-import-in-document"));
|
||||
var _nohtmllinkforpages = /*#__PURE__*/ _interop_require_default(require("./rules/no-html-link-for-pages"));
|
||||
var _noimgelement = /*#__PURE__*/ _interop_require_default(require("./rules/no-img-element"));
|
||||
var _nopagecustomfont = /*#__PURE__*/ _interop_require_default(require("./rules/no-page-custom-font"));
|
||||
var _noscriptcomponentinhead = /*#__PURE__*/ _interop_require_default(require("./rules/no-script-component-in-head"));
|
||||
var _nostyledjsxindocument = /*#__PURE__*/ _interop_require_default(require("./rules/no-styled-jsx-in-document"));
|
||||
var _nosyncscripts = /*#__PURE__*/ _interop_require_default(require("./rules/no-sync-scripts"));
|
||||
var _notitleindocumenthead = /*#__PURE__*/ _interop_require_default(require("./rules/no-title-in-document-head"));
|
||||
var _notypos = /*#__PURE__*/ _interop_require_default(require("./rules/no-typos"));
|
||||
var _nounwantedpolyfillio = /*#__PURE__*/ _interop_require_default(require("./rules/no-unwanted-polyfillio"));
|
||||
function _define_property(obj, key, value) {
|
||||
if (key in obj) {
|
||||
Object.defineProperty(obj, key, {
|
||||
value: value,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
} else {
|
||||
obj[key] = value;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
function _interop_require_default(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
function _object_spread(target) {
|
||||
for(var i = 1; i < arguments.length; i++){
|
||||
var source = arguments[i] != null ? arguments[i] : {};
|
||||
var ownKeys = Object.keys(source);
|
||||
if (typeof Object.getOwnPropertySymbols === "function") {
|
||||
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
||||
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
||||
}));
|
||||
}
|
||||
ownKeys.forEach(function(key) {
|
||||
_define_property(target, key, source[key]);
|
||||
});
|
||||
}
|
||||
return target;
|
||||
}
|
||||
var recommendedRules = {
|
||||
// warnings
|
||||
'@next/next/google-font-display': 'warn',
|
||||
'@next/next/google-font-preconnect': 'warn',
|
||||
'@next/next/next-script-for-ga': 'warn',
|
||||
'@next/next/no-async-client-component': 'warn',
|
||||
'@next/next/no-before-interactive-script-outside-document': 'warn',
|
||||
'@next/next/no-css-tags': 'warn',
|
||||
'@next/next/no-head-element': 'warn',
|
||||
'@next/next/no-html-link-for-pages': 'warn',
|
||||
'@next/next/no-img-element': 'warn',
|
||||
'@next/next/no-page-custom-font': 'warn',
|
||||
'@next/next/no-styled-jsx-in-document': 'warn',
|
||||
'@next/next/no-sync-scripts': 'warn',
|
||||
'@next/next/no-title-in-document-head': 'warn',
|
||||
'@next/next/no-typos': 'warn',
|
||||
'@next/next/no-unwanted-polyfillio': 'warn',
|
||||
// errors
|
||||
'@next/next/inline-script-id': 'error',
|
||||
'@next/next/no-assign-module-variable': 'error',
|
||||
'@next/next/no-document-import-in-page': 'error',
|
||||
'@next/next/no-duplicate-head': 'error',
|
||||
'@next/next/no-head-import-in-document': 'error',
|
||||
'@next/next/no-script-component-in-head': 'error'
|
||||
};
|
||||
var coreWebVitalsRules = {
|
||||
'@next/next/no-html-link-for-pages': 'error',
|
||||
'@next/next/no-sync-scripts': 'error'
|
||||
};
|
||||
var plugin = {
|
||||
meta: {
|
||||
name: '@next/eslint-plugin-next'
|
||||
},
|
||||
rules: {
|
||||
'google-font-display': _googlefontdisplay.default,
|
||||
'google-font-preconnect': _googlefontpreconnect.default,
|
||||
'inline-script-id': _inlinescriptid.default,
|
||||
'next-script-for-ga': _nextscriptforga.default,
|
||||
'no-assign-module-variable': _noassignmodulevariable.default,
|
||||
'no-async-client-component': _noasyncclientcomponent.default,
|
||||
'no-before-interactive-script-outside-document': _nobeforeinteractivescriptoutsidedocument.default,
|
||||
'no-css-tags': _nocsstags.default,
|
||||
'no-document-import-in-page': _nodocumentimportinpage.default,
|
||||
'no-duplicate-head': _noduplicatehead.default,
|
||||
'no-head-element': _noheadelement.default,
|
||||
'no-head-import-in-document': _noheadimportindocument.default,
|
||||
'no-html-link-for-pages': _nohtmllinkforpages.default,
|
||||
'no-img-element': _noimgelement.default,
|
||||
'no-page-custom-font': _nopagecustomfont.default,
|
||||
'no-script-component-in-head': _noscriptcomponentinhead.default,
|
||||
'no-styled-jsx-in-document': _nostyledjsxindocument.default,
|
||||
'no-sync-scripts': _nosyncscripts.default,
|
||||
'no-title-in-document-head': _notitleindocumenthead.default,
|
||||
'no-typos': _notypos.default,
|
||||
'no-unwanted-polyfillio': _nounwantedpolyfillio.default
|
||||
},
|
||||
configs: {}
|
||||
};
|
||||
Object.assign(plugin.configs, {
|
||||
'recommended-legacy': {
|
||||
plugins: [
|
||||
'@next/next'
|
||||
],
|
||||
rules: recommendedRules
|
||||
},
|
||||
'core-web-vitals-legacy': {
|
||||
plugins: [
|
||||
'@next/next'
|
||||
],
|
||||
extends: [
|
||||
'plugin:@next/next/recommended-legacy'
|
||||
],
|
||||
rules: coreWebVitalsRules
|
||||
},
|
||||
recommended: {
|
||||
name: 'next/recommended',
|
||||
plugins: {
|
||||
'@next/next': plugin
|
||||
},
|
||||
rules: recommendedRules
|
||||
},
|
||||
'core-web-vitals': {
|
||||
name: 'next/core-web-vitals',
|
||||
plugins: {
|
||||
'@next/next': plugin
|
||||
},
|
||||
rules: _object_spread({}, recommendedRules, coreWebVitalsRules)
|
||||
}
|
||||
});
|
||||
var _default = plugin;
|
||||
var rules = plugin.rules, configs = plugin.configs;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _definerule = require("../utils/define-rule");
|
||||
var _nodeattributes = /*#__PURE__*/ _interop_require_default(require("../utils/node-attributes"));
|
||||
function _interop_require_default(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
var url = 'https://nextjs.org/docs/messages/google-font-display';
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Enforce font-display behavior with Google Fonts.',
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
return {
|
||||
JSXOpeningElement: function JSXOpeningElement(node) {
|
||||
var message;
|
||||
if (node.name.name !== 'link') {
|
||||
return;
|
||||
}
|
||||
var attributes = new _nodeattributes.default(node);
|
||||
if (!attributes.has('href') || !attributes.hasValue('href')) {
|
||||
return;
|
||||
}
|
||||
var hrefValue = attributes.value('href');
|
||||
var isGoogleFont = typeof hrefValue === 'string' && hrefValue.startsWith('https://fonts.googleapis.com/css');
|
||||
if (isGoogleFont) {
|
||||
var params = new URLSearchParams(hrefValue.split('?', 2)[1]);
|
||||
var displayValue = params.get('display');
|
||||
if (!params.has('display')) {
|
||||
message = 'A font-display parameter is missing (adding `&display=optional` is recommended).';
|
||||
} else if (displayValue === 'auto' || displayValue === 'block' || displayValue === 'fallback') {
|
||||
message = "".concat(displayValue[0].toUpperCase() + displayValue.slice(1), " is not recommended.");
|
||||
}
|
||||
}
|
||||
if (message) {
|
||||
context.report({
|
||||
node: node,
|
||||
message: "".concat(message, " See: ").concat(url)
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _definerule = require("../utils/define-rule");
|
||||
var _nodeattributes = /*#__PURE__*/ _interop_require_default(require("../utils/node-attributes"));
|
||||
function _interop_require_default(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
var url = 'https://nextjs.org/docs/messages/google-font-preconnect';
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Ensure `preconnect` is used with Google Fonts.',
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
return {
|
||||
JSXOpeningElement: function JSXOpeningElement(node) {
|
||||
if (node.name.name !== 'link') {
|
||||
return;
|
||||
}
|
||||
var attributes = new _nodeattributes.default(node);
|
||||
if (!attributes.has('href') || !attributes.hasValue('href')) {
|
||||
return;
|
||||
}
|
||||
var hrefValue = attributes.value('href');
|
||||
var preconnectMissing = !attributes.has('rel') || !attributes.hasValue('rel') || attributes.value('rel') !== 'preconnect';
|
||||
if (typeof hrefValue === 'string' && hrefValue.startsWith('https://fonts.gstatic.com') && preconnectMissing) {
|
||||
context.report({
|
||||
node: node,
|
||||
message: '`rel="preconnect"` is missing from Google Font. See: '.concat(url)
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _definerule = require("../utils/define-rule");
|
||||
var url = 'https://nextjs.org/docs/messages/inline-script-id';
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Enforce `id` attribute on `next/script` components with inline content.',
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
var nextScriptImportName = null;
|
||||
return {
|
||||
ImportDeclaration: function ImportDeclaration(node) {
|
||||
if (node.source.value === 'next/script') {
|
||||
nextScriptImportName = node.specifiers[0].local.name;
|
||||
}
|
||||
},
|
||||
JSXElement: function JSXElement(node) {
|
||||
if (nextScriptImportName == null) return;
|
||||
if (node.openingElement && node.openingElement.name && node.openingElement.name.name !== nextScriptImportName) {
|
||||
return;
|
||||
}
|
||||
var attributeNames = new Set();
|
||||
var hasNonCheckableSpreadAttribute = false;
|
||||
node.openingElement.attributes.forEach(function(attribute) {
|
||||
// Early return if we already have a non-checkable spread attribute, for better performance
|
||||
if (hasNonCheckableSpreadAttribute) return;
|
||||
if (attribute.type === 'JSXAttribute') {
|
||||
attributeNames.add(attribute.name.name);
|
||||
} else if (attribute.type === 'JSXSpreadAttribute') {
|
||||
if (attribute.argument && attribute.argument.properties) {
|
||||
attribute.argument.properties.forEach(function(property) {
|
||||
attributeNames.add(property.key.name);
|
||||
});
|
||||
} else {
|
||||
// JSXSpreadAttribute without properties is not checkable
|
||||
hasNonCheckableSpreadAttribute = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
// https://github.com/vercel/next.js/issues/34030
|
||||
// If there is a non-checkable spread attribute, we simply ignore them
|
||||
if (hasNonCheckableSpreadAttribute) return;
|
||||
if (node.children.length > 0 || attributeNames.has('dangerouslySetInnerHTML')) {
|
||||
if (!attributeNames.has('id')) {
|
||||
context.report({
|
||||
node: node,
|
||||
message: "`next/script` components with inline content must specify an `id` attribute. See: ".concat(url)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _definerule = require("../utils/define-rule");
|
||||
var _nodeattributes = /*#__PURE__*/ _interop_require_default(require("../utils/node-attributes"));
|
||||
function _interop_require_default(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
var GOOGLE_ANALYTICS_URL = 'www.google-analytics.com/analytics.js';
|
||||
var GOOGLE_TAG_MANAGER_URL = 'www.googletagmanager.com/gtag/js';
|
||||
var GOOGLE_ANALYTICS_SRC = GOOGLE_ANALYTICS_URL;
|
||||
var GOOGLE_TAG_MANAGER_SRC = 'www.googletagmanager.com/gtm.js';
|
||||
var description = 'Prefer `@next/third-parties/google` when using the inline script for Google Analytics and Tag Manager.';
|
||||
var url = 'https://nextjs.org/docs/messages/next-script-for-ga';
|
||||
var ERROR_MSG_GOOGLE_ANALYTICS = "Prefer `GoogleAnalytics` component from `@next/third-parties/google` when using the inline script for Google Analytics. See: ".concat(url);
|
||||
var ERROR_MSG_GOOGLE_TAG_MANAGER = "Prefer `GoogleTagManager` component from `@next/third-parties/google` when using the inline script for Google Tag Manager. See: ".concat(url);
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: description,
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
return {
|
||||
JSXOpeningElement: function JSXOpeningElement(node) {
|
||||
if (node.name.name !== 'script') {
|
||||
return;
|
||||
}
|
||||
if (node.attributes.length === 0) {
|
||||
return;
|
||||
}
|
||||
var attributes = new _nodeattributes.default(node);
|
||||
var src = attributes.value('src');
|
||||
// Check if the Alternative async tag is being used to add GA.
|
||||
// https://developers.google.com/analytics/devguides/collection/analyticsjs#alternative_async_tag
|
||||
// https://developers.google.com/analytics/devguides/collection/gtagjs
|
||||
if (typeof src === 'string' && src.includes(GOOGLE_ANALYTICS_URL)) {
|
||||
return context.report({
|
||||
node: node,
|
||||
message: ERROR_MSG_GOOGLE_ANALYTICS
|
||||
});
|
||||
} else if (typeof src === 'string' && src.includes(GOOGLE_TAG_MANAGER_URL)) {
|
||||
return context.report({
|
||||
node: node,
|
||||
message: ERROR_MSG_GOOGLE_TAG_MANAGER
|
||||
});
|
||||
}
|
||||
var dangerouslySetInnerHTML = attributes.value('dangerouslySetInnerHTML');
|
||||
// Check if inline script is being used to add GA.
|
||||
// https://developers.google.com/analytics/devguides/collection/analyticsjs#the_google_analytics_tag
|
||||
// https://developers.google.com/tag-manager/quickstart
|
||||
if (dangerouslySetInnerHTML && dangerouslySetInnerHTML.length > 0) {
|
||||
var _quasis__value, _quasis_;
|
||||
var quasis = dangerouslySetInnerHTML[0].value.quasis;
|
||||
var htmlContent = quasis === null || quasis === void 0 ? void 0 : (_quasis_ = quasis[0]) === null || _quasis_ === void 0 ? void 0 : (_quasis__value = _quasis_.value) === null || _quasis__value === void 0 ? void 0 : _quasis__value.raw;
|
||||
if (htmlContent && htmlContent.includes(GOOGLE_ANALYTICS_SRC)) {
|
||||
context.report({
|
||||
node: node,
|
||||
message: ERROR_MSG_GOOGLE_ANALYTICS
|
||||
});
|
||||
} else if (htmlContent && htmlContent.includes(GOOGLE_TAG_MANAGER_SRC)) {
|
||||
context.report({
|
||||
node: node,
|
||||
message: ERROR_MSG_GOOGLE_TAG_MANAGER
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _definerule = require("../utils/define-rule");
|
||||
var url = 'https://nextjs.org/docs/messages/no-assign-module-variable';
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Prevent assignment to the `module` variable.',
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
return {
|
||||
VariableDeclaration: function VariableDeclaration(node) {
|
||||
// Checks node.declarations array for variable with id.name of `module`
|
||||
var moduleVariableFound = node.declarations.some(function(declaration) {
|
||||
if ('name' in declaration.id) {
|
||||
return declaration.id.name === 'module';
|
||||
}
|
||||
return false;
|
||||
});
|
||||
// Return early if no `module` variable is found
|
||||
if (!moduleVariableFound) {
|
||||
return;
|
||||
}
|
||||
context.report({
|
||||
node: node,
|
||||
message: "Do not assign to the variable `module`. See: ".concat(url)
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _definerule = require("../utils/define-rule");
|
||||
var url = 'https://nextjs.org/docs/messages/no-async-client-component';
|
||||
var description = 'Prevent Client Components from being async functions.';
|
||||
var message = "".concat(description, " See: ").concat(url);
|
||||
function isCapitalized(str) {
|
||||
return /[A-Z]/.test(str === null || str === void 0 ? void 0 : str[0]);
|
||||
}
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: description,
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
return {
|
||||
Program: function Program(node) {
|
||||
var isClientComponent = false;
|
||||
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
||||
try {
|
||||
var _loop = function() {
|
||||
var block = _step.value;
|
||||
if (block.type === 'ExpressionStatement' && block.expression.type === 'Literal' && block.expression.value === 'use client') {
|
||||
isClientComponent = true;
|
||||
}
|
||||
if (block.type === 'ExportDefaultDeclaration' && isClientComponent) {
|
||||
var _block_declaration;
|
||||
// export default async function MyComponent() {...}
|
||||
if (((_block_declaration = block.declaration) === null || _block_declaration === void 0 ? void 0 : _block_declaration.type) === 'FunctionDeclaration' && block.declaration.async && isCapitalized(block.declaration.id.name)) {
|
||||
context.report({
|
||||
node: block,
|
||||
message: message
|
||||
});
|
||||
}
|
||||
// async function MyComponent() {...}; export default MyComponent;
|
||||
if (block.declaration.type === 'Identifier' && isCapitalized(block.declaration.name)) {
|
||||
var targetName = block.declaration.name;
|
||||
var functionDeclaration = node.body.find(function(localBlock) {
|
||||
if (localBlock.type === 'FunctionDeclaration' && localBlock.id.name === targetName) return true;
|
||||
if (localBlock.type === 'VariableDeclaration' && localBlock.declarations.find(function(declaration) {
|
||||
var _declaration_id;
|
||||
return ((_declaration_id = declaration.id) === null || _declaration_id === void 0 ? void 0 : _declaration_id.type) === 'Identifier' && declaration.id.name === targetName;
|
||||
})) return true;
|
||||
return false;
|
||||
});
|
||||
if ((functionDeclaration === null || functionDeclaration === void 0 ? void 0 : functionDeclaration.type) === 'FunctionDeclaration' && functionDeclaration.async) {
|
||||
context.report({
|
||||
node: functionDeclaration,
|
||||
message: message
|
||||
});
|
||||
}
|
||||
if ((functionDeclaration === null || functionDeclaration === void 0 ? void 0 : functionDeclaration.type) === 'VariableDeclaration') {
|
||||
var _varDeclarator_init;
|
||||
var varDeclarator = functionDeclaration.declarations.find(function(declaration) {
|
||||
var _declaration_id;
|
||||
return ((_declaration_id = declaration.id) === null || _declaration_id === void 0 ? void 0 : _declaration_id.type) === 'Identifier' && declaration.id.name === targetName;
|
||||
});
|
||||
if ((varDeclarator === null || varDeclarator === void 0 ? void 0 : (_varDeclarator_init = varDeclarator.init) === null || _varDeclarator_init === void 0 ? void 0 : _varDeclarator_init.type) === 'ArrowFunctionExpression' && varDeclarator.init.async) {
|
||||
context.report({
|
||||
node: functionDeclaration,
|
||||
message: message
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
for(var _iterator = node.body[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally{
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally{
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
Generated
Vendored
+104
@@ -0,0 +1,104 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _definerule = require("../utils/define-rule");
|
||||
var _path = /*#__PURE__*/ _interop_require_wildcard(require("path"));
|
||||
function _getRequireWildcardCache(nodeInterop) {
|
||||
if (typeof WeakMap !== "function") return null;
|
||||
var cacheBabelInterop = new WeakMap();
|
||||
var cacheNodeInterop = new WeakMap();
|
||||
return (_getRequireWildcardCache = function(nodeInterop) {
|
||||
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
||||
})(nodeInterop);
|
||||
}
|
||||
function _interop_require_wildcard(obj, nodeInterop) {
|
||||
if (!nodeInterop && obj && obj.__esModule) {
|
||||
return obj;
|
||||
}
|
||||
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
||||
return {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
var cache = _getRequireWildcardCache(nodeInterop);
|
||||
if (cache && cache.has(obj)) {
|
||||
return cache.get(obj);
|
||||
}
|
||||
var newObj = {
|
||||
__proto__: null
|
||||
};
|
||||
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
||||
for(var key in obj){
|
||||
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
||||
if (desc && (desc.get || desc.set)) {
|
||||
Object.defineProperty(newObj, key, desc);
|
||||
} else {
|
||||
newObj[key] = obj[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
newObj.default = obj;
|
||||
if (cache) {
|
||||
cache.set(obj, newObj);
|
||||
}
|
||||
return newObj;
|
||||
}
|
||||
var url = 'https://nextjs.org/docs/messages/no-before-interactive-script-outside-document';
|
||||
var convertToCorrectSeparator = function(str) {
|
||||
return str.replace(/[\\/]/g, _path.sep);
|
||||
};
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: "Prevent usage of `next/script`'s `beforeInteractive` strategy outside of `pages/_document.js`.",
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
var scriptImportName = null;
|
||||
return {
|
||||
'ImportDeclaration[source.value="next/script"] > ImportDefaultSpecifier': function(node) {
|
||||
scriptImportName = node.local.name;
|
||||
},
|
||||
JSXOpeningElement: function JSXOpeningElement(node) {
|
||||
var pathname = convertToCorrectSeparator(context.filename);
|
||||
var isInAppDir = pathname.includes("".concat(_path.sep, "app").concat(_path.sep));
|
||||
// This rule shouldn't fire in `app/`
|
||||
if (isInAppDir) {
|
||||
return;
|
||||
}
|
||||
if (!scriptImportName) {
|
||||
return;
|
||||
}
|
||||
if (node.name && node.name.name !== scriptImportName) {
|
||||
return;
|
||||
}
|
||||
var strategy = node.attributes.find(function(child) {
|
||||
return child.name && child.name.name === 'strategy';
|
||||
});
|
||||
if (!strategy || !strategy.value || strategy.value.value !== 'beforeInteractive') {
|
||||
return;
|
||||
}
|
||||
var document = context.filename.split('pages', 2)[1];
|
||||
if (document && _path.parse(document).name.startsWith('_document')) {
|
||||
return;
|
||||
}
|
||||
context.report({
|
||||
node: node,
|
||||
message: "`next/script`'s `beforeInteractive` strategy should not be used outside of `pages/_document.js`. See: ".concat(url)
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _definerule = require("../utils/define-rule");
|
||||
var url = 'https://nextjs.org/docs/messages/no-css-tags';
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Prevent manual stylesheet tags.',
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
return {
|
||||
JSXOpeningElement: function JSXOpeningElement(node) {
|
||||
if (node.name.name !== 'link') {
|
||||
return;
|
||||
}
|
||||
if (node.attributes.length === 0) {
|
||||
return;
|
||||
}
|
||||
var attributes = node.attributes.filter(function(attr) {
|
||||
return attr.type === 'JSXAttribute';
|
||||
});
|
||||
if (attributes.find(function(attr) {
|
||||
return attr.name.name === 'rel' && attr.value.value === 'stylesheet';
|
||||
}) && attributes.find(function(attr) {
|
||||
return attr.name.name === 'href' && attr.value.type === 'Literal' && !/^https?/.test(attr.value.value);
|
||||
})) {
|
||||
context.report({
|
||||
node: node,
|
||||
message: "Do not include stylesheets manually. See: ".concat(url)
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _definerule = require("../utils/define-rule");
|
||||
var _path = /*#__PURE__*/ _interop_require_wildcard(require("path"));
|
||||
function _getRequireWildcardCache(nodeInterop) {
|
||||
if (typeof WeakMap !== "function") return null;
|
||||
var cacheBabelInterop = new WeakMap();
|
||||
var cacheNodeInterop = new WeakMap();
|
||||
return (_getRequireWildcardCache = function(nodeInterop) {
|
||||
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
||||
})(nodeInterop);
|
||||
}
|
||||
function _interop_require_wildcard(obj, nodeInterop) {
|
||||
if (!nodeInterop && obj && obj.__esModule) {
|
||||
return obj;
|
||||
}
|
||||
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
||||
return {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
var cache = _getRequireWildcardCache(nodeInterop);
|
||||
if (cache && cache.has(obj)) {
|
||||
return cache.get(obj);
|
||||
}
|
||||
var newObj = {
|
||||
__proto__: null
|
||||
};
|
||||
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
||||
for(var key in obj){
|
||||
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
||||
if (desc && (desc.get || desc.set)) {
|
||||
Object.defineProperty(newObj, key, desc);
|
||||
} else {
|
||||
newObj[key] = obj[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
newObj.default = obj;
|
||||
if (cache) {
|
||||
cache.set(obj, newObj);
|
||||
}
|
||||
return newObj;
|
||||
}
|
||||
var url = 'https://nextjs.org/docs/messages/no-document-import-in-page';
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Prevent importing `next/document` outside of `pages/_document.js`.',
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
return {
|
||||
ImportDeclaration: function ImportDeclaration(node) {
|
||||
if (node.source.value !== 'next/document') {
|
||||
return;
|
||||
}
|
||||
var paths = context.filename.split('pages');
|
||||
var page = paths[paths.length - 1];
|
||||
if (!page || page.startsWith("".concat(_path.sep, "_document")) || page.startsWith("".concat(_path.posix.sep, "_document"))) {
|
||||
return;
|
||||
}
|
||||
context.report({
|
||||
node: node,
|
||||
message: "`<Document />` from `next/document` should not be imported outside of `pages/_document.js`. See: ".concat(url)
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _definerule = require("../utils/define-rule");
|
||||
var url = 'https://nextjs.org/docs/messages/no-duplicate-head';
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Prevent duplicate usage of `<Head>` in `pages/_document.js`.',
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
var sourceCode = context.sourceCode;
|
||||
var documentImportName;
|
||||
return {
|
||||
ImportDeclaration: function ImportDeclaration(node) {
|
||||
if (node.source.value === 'next/document') {
|
||||
var documentImport = node.specifiers.find(function(param) {
|
||||
var type = param.type;
|
||||
return type === 'ImportDefaultSpecifier';
|
||||
});
|
||||
if (documentImport && documentImport.local) {
|
||||
documentImportName = documentImport.local.name;
|
||||
}
|
||||
}
|
||||
},
|
||||
ReturnStatement: function ReturnStatement(node) {
|
||||
var ancestors = sourceCode.getAncestors(node);
|
||||
var documentClass = ancestors.find(function(ancestorNode) {
|
||||
return ancestorNode.type === 'ClassDeclaration' && ancestorNode.superClass && 'name' in ancestorNode.superClass && ancestorNode.superClass.name === documentImportName;
|
||||
});
|
||||
if (!documentClass) {
|
||||
return;
|
||||
}
|
||||
if (node.argument && 'children' in node.argument && node.argument.children) {
|
||||
// @ts-expect-error - `node.argument` could be a `JSXElement` which has property `children`
|
||||
var headComponents = node.argument.children.filter(function(childrenNode) {
|
||||
return childrenNode.openingElement && childrenNode.openingElement.name && childrenNode.openingElement.name.name === 'Head';
|
||||
});
|
||||
if (headComponents.length > 1) {
|
||||
for(var i = 1; i < headComponents.length; i++){
|
||||
context.report({
|
||||
node: headComponents[i],
|
||||
message: "Do not include multiple instances of `<Head/>`. See: ".concat(url)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
||||
var _definerule = require("../utils/define-rule");
|
||||
function _interop_require_default(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
var url = 'https://nextjs.org/docs/messages/no-head-element';
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Prevent usage of `<head>` element.',
|
||||
category: 'HTML',
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
return {
|
||||
JSXOpeningElement: function JSXOpeningElement(node) {
|
||||
var paths = context.filename;
|
||||
var isInAppDir = function() {
|
||||
return paths.includes("app".concat(_path.default.sep)) || paths.includes("app".concat(_path.default.posix.sep));
|
||||
};
|
||||
// Only lint the <head> element in pages directory
|
||||
if (node.name.name !== 'head' || isInAppDir()) {
|
||||
return;
|
||||
}
|
||||
context.report({
|
||||
node: node,
|
||||
message: "Do not use `<head>` element. Use `<Head />` from `next/head` instead. See: ".concat(url)
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _definerule = require("../utils/define-rule");
|
||||
var _path = /*#__PURE__*/ _interop_require_wildcard(require("path"));
|
||||
function _getRequireWildcardCache(nodeInterop) {
|
||||
if (typeof WeakMap !== "function") return null;
|
||||
var cacheBabelInterop = new WeakMap();
|
||||
var cacheNodeInterop = new WeakMap();
|
||||
return (_getRequireWildcardCache = function(nodeInterop) {
|
||||
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
||||
})(nodeInterop);
|
||||
}
|
||||
function _interop_require_wildcard(obj, nodeInterop) {
|
||||
if (!nodeInterop && obj && obj.__esModule) {
|
||||
return obj;
|
||||
}
|
||||
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
||||
return {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
var cache = _getRequireWildcardCache(nodeInterop);
|
||||
if (cache && cache.has(obj)) {
|
||||
return cache.get(obj);
|
||||
}
|
||||
var newObj = {
|
||||
__proto__: null
|
||||
};
|
||||
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
||||
for(var key in obj){
|
||||
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
||||
if (desc && (desc.get || desc.set)) {
|
||||
Object.defineProperty(newObj, key, desc);
|
||||
} else {
|
||||
newObj[key] = obj[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
newObj.default = obj;
|
||||
if (cache) {
|
||||
cache.set(obj, newObj);
|
||||
}
|
||||
return newObj;
|
||||
}
|
||||
var url = 'https://nextjs.org/docs/messages/no-head-import-in-document';
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Prevent usage of `next/head` in `pages/_document.js`.',
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
return {
|
||||
ImportDeclaration: function ImportDeclaration(node) {
|
||||
if (node.source.value !== 'next/head') {
|
||||
return;
|
||||
}
|
||||
var document = context.filename.split('pages', 2)[1];
|
||||
if (!document) {
|
||||
return;
|
||||
}
|
||||
var _path_parse = _path.parse(document), name = _path_parse.name, dir = _path_parse.dir;
|
||||
if (name.startsWith('_document') || dir === '/_document' && name === 'index') {
|
||||
context.report({
|
||||
node: node,
|
||||
message: "`next/head` should not be imported in `pages".concat(document, "`. Use `<Head />` from `next/document` instead. See: ").concat(url)
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+245
@@ -0,0 +1,245 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _definerule = require("../utils/define-rule");
|
||||
var _path = /*#__PURE__*/ _interop_require_wildcard(require("path"));
|
||||
var _fs = /*#__PURE__*/ _interop_require_wildcard(require("fs"));
|
||||
var _getrootdirs = require("../utils/get-root-dirs");
|
||||
var _url = require("../utils/url");
|
||||
function _array_like_to_array(arr, len) {
|
||||
if (len == null || len > arr.length) len = arr.length;
|
||||
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
||||
return arr2;
|
||||
}
|
||||
function _array_with_holes(arr) {
|
||||
if (Array.isArray(arr)) return arr;
|
||||
}
|
||||
function _array_without_holes(arr) {
|
||||
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
||||
}
|
||||
function _getRequireWildcardCache(nodeInterop) {
|
||||
if (typeof WeakMap !== "function") return null;
|
||||
var cacheBabelInterop = new WeakMap();
|
||||
var cacheNodeInterop = new WeakMap();
|
||||
return (_getRequireWildcardCache = function(nodeInterop) {
|
||||
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
||||
})(nodeInterop);
|
||||
}
|
||||
function _interop_require_wildcard(obj, nodeInterop) {
|
||||
if (!nodeInterop && obj && obj.__esModule) {
|
||||
return obj;
|
||||
}
|
||||
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
||||
return {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
var cache = _getRequireWildcardCache(nodeInterop);
|
||||
if (cache && cache.has(obj)) {
|
||||
return cache.get(obj);
|
||||
}
|
||||
var newObj = {
|
||||
__proto__: null
|
||||
};
|
||||
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
||||
for(var key in obj){
|
||||
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
||||
if (desc && (desc.get || desc.set)) {
|
||||
Object.defineProperty(newObj, key, desc);
|
||||
} else {
|
||||
newObj[key] = obj[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
newObj.default = obj;
|
||||
if (cache) {
|
||||
cache.set(obj, newObj);
|
||||
}
|
||||
return newObj;
|
||||
}
|
||||
function _iterable_to_array(iter) {
|
||||
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
||||
}
|
||||
function _iterable_to_array_limit(arr, i) {
|
||||
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
||||
if (_i == null) return;
|
||||
var _arr = [];
|
||||
var _n = true;
|
||||
var _d = false;
|
||||
var _s, _e;
|
||||
try {
|
||||
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
||||
_arr.push(_s.value);
|
||||
if (i && _arr.length === i) break;
|
||||
}
|
||||
} catch (err) {
|
||||
_d = true;
|
||||
_e = err;
|
||||
} finally{
|
||||
try {
|
||||
if (!_n && _i["return"] != null) _i["return"]();
|
||||
} finally{
|
||||
if (_d) throw _e;
|
||||
}
|
||||
}
|
||||
return _arr;
|
||||
}
|
||||
function _non_iterable_rest() {
|
||||
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
||||
}
|
||||
function _non_iterable_spread() {
|
||||
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
||||
}
|
||||
function _sliced_to_array(arr, i) {
|
||||
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
||||
}
|
||||
function _to_consumable_array(arr) {
|
||||
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
||||
}
|
||||
function _unsupported_iterable_to_array(o, minLen) {
|
||||
if (!o) return;
|
||||
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
||||
var n = Object.prototype.toString.call(o).slice(8, -1);
|
||||
if (n === "Object" && o.constructor) n = o.constructor.name;
|
||||
if (n === "Map" || n === "Set") return Array.from(n);
|
||||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
||||
}
|
||||
var pagesDirWarning = (0, _url.execOnce)(function(pagesDirs) {
|
||||
console.warn("Pages directory cannot be found at ".concat(pagesDirs.join(' or '), ". ") + 'If using a custom path, please configure with the `no-html-link-for-pages` rule in your eslint config file.');
|
||||
});
|
||||
// Cache for fs.existsSync lookup.
|
||||
// Prevent multiple blocking IO requests that have already been calculated.
|
||||
var fsExistsSyncCache = {};
|
||||
var memoize = function(fn) {
|
||||
var cache = {};
|
||||
return function() {
|
||||
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
var key = JSON.stringify(args);
|
||||
if (cache[key] === undefined) {
|
||||
cache[key] = fn.apply(void 0, _to_consumable_array(args));
|
||||
}
|
||||
return cache[key];
|
||||
};
|
||||
};
|
||||
var cachedGetUrlFromPagesDirectories = memoize(_url.getUrlFromPagesDirectories);
|
||||
var cachedGetUrlFromAppDirectory = memoize(_url.getUrlFromAppDirectory);
|
||||
var url = 'https://nextjs.org/docs/messages/no-html-link-for-pages';
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Prevent usage of `<a>` elements to navigate to internal Next.js pages.',
|
||||
category: 'HTML',
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: [
|
||||
{
|
||||
oneOf: [
|
||||
{
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
type: 'array',
|
||||
uniqueItems: true,
|
||||
items: {
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
/**
|
||||
* Creates an ESLint rule listener.
|
||||
*/ create: function create(context) {
|
||||
var ruleOptions = context.options;
|
||||
var _ruleOptions = _sliced_to_array(ruleOptions, 1), customPagesDirectory = _ruleOptions[0];
|
||||
var rootDirs = (0, _getrootdirs.getRootDirs)(context);
|
||||
var pagesDirs = (customPagesDirectory ? [
|
||||
customPagesDirectory
|
||||
] : rootDirs.map(function(dir) {
|
||||
return [
|
||||
_path.join(dir, 'pages'),
|
||||
_path.join(dir, 'src', 'pages')
|
||||
];
|
||||
})).flat();
|
||||
var foundPagesDirs = pagesDirs.filter(function(dir) {
|
||||
if (fsExistsSyncCache[dir] === undefined) {
|
||||
fsExistsSyncCache[dir] = _fs.existsSync(dir);
|
||||
}
|
||||
return fsExistsSyncCache[dir];
|
||||
});
|
||||
var appDirs = rootDirs.map(function(dir) {
|
||||
return [
|
||||
_path.join(dir, 'app'),
|
||||
_path.join(dir, 'src', 'app')
|
||||
];
|
||||
}).flat();
|
||||
var foundAppDirs = appDirs.filter(function(dir) {
|
||||
if (fsExistsSyncCache[dir] === undefined) {
|
||||
fsExistsSyncCache[dir] = _fs.existsSync(dir);
|
||||
}
|
||||
return fsExistsSyncCache[dir];
|
||||
});
|
||||
// warn if there are no pages and app directories
|
||||
if (foundPagesDirs.length === 0 && foundAppDirs.length === 0) {
|
||||
pagesDirWarning(pagesDirs);
|
||||
return {};
|
||||
}
|
||||
var pageUrls = cachedGetUrlFromPagesDirectories('/', foundPagesDirs);
|
||||
var appDirUrls = cachedGetUrlFromAppDirectory('/', foundAppDirs);
|
||||
var allUrlRegex = _to_consumable_array(pageUrls).concat(_to_consumable_array(appDirUrls));
|
||||
return {
|
||||
JSXOpeningElement: function JSXOpeningElement(node) {
|
||||
if (node.name.name !== 'a') {
|
||||
return;
|
||||
}
|
||||
if (node.attributes.length === 0) {
|
||||
return;
|
||||
}
|
||||
var target = node.attributes.find(function(attr) {
|
||||
return attr.type === 'JSXAttribute' && attr.name.name === 'target';
|
||||
});
|
||||
if (target && target.value.value === '_blank') {
|
||||
return;
|
||||
}
|
||||
var href = node.attributes.find(function(attr) {
|
||||
return attr.type === 'JSXAttribute' && attr.name.name === 'href';
|
||||
});
|
||||
if (!href || href.value && href.value.type !== 'Literal') {
|
||||
return;
|
||||
}
|
||||
var hasDownloadAttr = node.attributes.find(function(attr) {
|
||||
return attr.type === 'JSXAttribute' && attr.name.name === 'download';
|
||||
});
|
||||
if (hasDownloadAttr) {
|
||||
return;
|
||||
}
|
||||
var hrefPath = (0, _url.normalizeURL)(href.value.value);
|
||||
// Outgoing links are ignored
|
||||
if (/^(https?:\/\/|\/\/)/.test(hrefPath)) {
|
||||
return;
|
||||
}
|
||||
allUrlRegex.forEach(function(foundUrl) {
|
||||
if (foundUrl.test((0, _url.normalizeURL)(hrefPath))) {
|
||||
context.report({
|
||||
node: node,
|
||||
message: "Do not use an `<a>` element to navigate to `".concat(hrefPath, "`. Use `<Link />` from `next/link` instead. See: ").concat(url)
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
||||
var _definerule = require("../utils/define-rule");
|
||||
function _interop_require_default(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
var url = 'https://nextjs.org/docs/messages/no-img-element';
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Prevent usage of `<img>` element due to slower LCP and higher bandwidth.',
|
||||
category: 'HTML',
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
// Get relative path of the file
|
||||
var relativePath = context.filename.replace(_path.default.sep, '/').replace(context.cwd, '').replace(/^\//, '');
|
||||
var isAppDir = /^(src\/)?app\//.test(relativePath);
|
||||
return {
|
||||
JSXOpeningElement: function JSXOpeningElement(node) {
|
||||
var _node_parent_parent_openingElement_name, _node_parent_parent_openingElement, _node_parent_parent, _node_parent;
|
||||
if (node.name.name !== 'img') {
|
||||
return;
|
||||
}
|
||||
if (node.attributes.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (((_node_parent = node.parent) === null || _node_parent === void 0 ? void 0 : (_node_parent_parent = _node_parent.parent) === null || _node_parent_parent === void 0 ? void 0 : (_node_parent_parent_openingElement = _node_parent_parent.openingElement) === null || _node_parent_parent_openingElement === void 0 ? void 0 : (_node_parent_parent_openingElement_name = _node_parent_parent_openingElement.name) === null || _node_parent_parent_openingElement_name === void 0 ? void 0 : _node_parent_parent_openingElement_name.name) === 'picture') {
|
||||
return;
|
||||
}
|
||||
// If is metadata route files, ignore
|
||||
// e.g. opengraph-image.js, twitter-image.js, icon.js
|
||||
if (isAppDir && /\/opengraph-image|twitter-image|icon\.\w+$/.test(relativePath)) return;
|
||||
context.report({
|
||||
node: node,
|
||||
message: "Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` or a custom image loader to automatically optimize images. This may incur additional usage or cost from your provider. See: ".concat(url)
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _definerule = require("../utils/define-rule");
|
||||
var _nodeattributes = /*#__PURE__*/ _interop_require_default(require("../utils/node-attributes"));
|
||||
var _path = require("path");
|
||||
function _interop_require_default(obj) {
|
||||
return obj && obj.__esModule ? obj : {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
var url = 'https://nextjs.org/docs/messages/no-page-custom-font';
|
||||
function isIdentifierMatch(id1, id2) {
|
||||
return id1 === null && id2 === null || id1 && id2 && id1.name === id2.name;
|
||||
}
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Prevent page-only custom fonts.',
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
var sourceCode = context.sourceCode;
|
||||
var paths = context.filename.split('pages');
|
||||
var page = paths[paths.length - 1];
|
||||
// outside of a file within `pages`, bail
|
||||
if (!page) {
|
||||
return {};
|
||||
}
|
||||
var is_Document = page.startsWith("".concat(_path.sep, "_document")) || page.startsWith("".concat(_path.posix.sep, "_document"));
|
||||
var documentImportName;
|
||||
var localDefaultExportId;
|
||||
var exportDeclarationType;
|
||||
return {
|
||||
ImportDeclaration: function ImportDeclaration(node) {
|
||||
if (node.source.value === 'next/document') {
|
||||
var documentImport = node.specifiers.find(function(param) {
|
||||
var type = param.type;
|
||||
return type === 'ImportDefaultSpecifier';
|
||||
});
|
||||
if (documentImport && documentImport.local) {
|
||||
documentImportName = documentImport.local.name;
|
||||
}
|
||||
}
|
||||
},
|
||||
ExportDefaultDeclaration: function ExportDefaultDeclaration(node) {
|
||||
exportDeclarationType = node.declaration.type;
|
||||
if (node.declaration.type === 'FunctionDeclaration') {
|
||||
localDefaultExportId = node.declaration.id;
|
||||
return;
|
||||
}
|
||||
if (node.declaration.type === 'ClassDeclaration' && node.declaration.superClass && 'name' in node.declaration.superClass && node.declaration.superClass.name === documentImportName) {
|
||||
localDefaultExportId = node.declaration.id;
|
||||
}
|
||||
},
|
||||
JSXOpeningElement: function JSXOpeningElement(node) {
|
||||
if (node.name.name !== 'link') {
|
||||
return;
|
||||
}
|
||||
var ancestors = sourceCode.getAncestors(node);
|
||||
// if `export default <name>` is further down within the file after the
|
||||
// currently traversed component, then `localDefaultExportName` will
|
||||
// still be undefined
|
||||
if (!localDefaultExportId) {
|
||||
// find the top level of the module
|
||||
var program = ancestors.find(function(ancestor) {
|
||||
return ancestor.type === 'Program';
|
||||
});
|
||||
// go over each token to find the combination of `export default <name>`
|
||||
for(var i = 0; i <= program.tokens.length - 1; i++){
|
||||
if (localDefaultExportId) {
|
||||
break;
|
||||
}
|
||||
var token = program.tokens[i];
|
||||
if (token.type === 'Keyword' && token.value === 'export') {
|
||||
var nextToken = program.tokens[i + 1];
|
||||
if (nextToken && nextToken.type === 'Keyword' && nextToken.value === 'default') {
|
||||
var maybeIdentifier = program.tokens[i + 2];
|
||||
if (maybeIdentifier && maybeIdentifier.type === 'Identifier') {
|
||||
localDefaultExportId = {
|
||||
name: maybeIdentifier.value
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var parentComponent = ancestors.find(function(ancestor) {
|
||||
// export default class ... extends ...
|
||||
if (exportDeclarationType === 'ClassDeclaration') {
|
||||
return ancestor.type === exportDeclarationType && 'superClass' in ancestor && ancestor.superClass && 'name' in ancestor.superClass && ancestor.superClass.name === documentImportName;
|
||||
}
|
||||
if ('id' in ancestor) {
|
||||
// export default function ...
|
||||
if (exportDeclarationType === 'FunctionDeclaration') {
|
||||
return ancestor.type === exportDeclarationType && isIdentifierMatch(ancestor.id, localDefaultExportId);
|
||||
}
|
||||
// function ...() {} export default ...
|
||||
// class ... extends ...; export default ...
|
||||
return isIdentifierMatch(ancestor.id, localDefaultExportId);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
// file starts with _document and this <link /> is within the default export
|
||||
if (is_Document && parentComponent) {
|
||||
return;
|
||||
}
|
||||
var attributes = new _nodeattributes.default(node);
|
||||
if (!attributes.has('href') || !attributes.hasValue('href')) {
|
||||
return;
|
||||
}
|
||||
var hrefValue = attributes.value('href');
|
||||
var isGoogleFont = typeof hrefValue === 'string' && hrefValue.startsWith('https://fonts.googleapis.com/css');
|
||||
if (isGoogleFont) {
|
||||
var end = "This is discouraged. See: ".concat(url);
|
||||
var message = is_Document ? "Using `<link />` outside of `<Head>` will disable automatic font optimization. ".concat(end) : "Custom fonts not added in `pages/_document.js` will only load for a single page. ".concat(end);
|
||||
context.report({
|
||||
node: node,
|
||||
message: message
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _definerule = require("../utils/define-rule");
|
||||
var url = 'https://nextjs.org/docs/messages/no-script-component-in-head';
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Prevent usage of `next/script` in `next/head` component.',
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
var isNextHead = null;
|
||||
return {
|
||||
ImportDeclaration: function ImportDeclaration(node) {
|
||||
if (node.source.value === 'next/head') {
|
||||
isNextHead = node.source.value;
|
||||
}
|
||||
if (node.source.value !== 'next/script') {
|
||||
return;
|
||||
}
|
||||
},
|
||||
JSXElement: function JSXElement(node) {
|
||||
if (!isNextHead) {
|
||||
return;
|
||||
}
|
||||
if (node.openingElement && node.openingElement.name && node.openingElement.name.name !== 'Head') {
|
||||
return;
|
||||
}
|
||||
var scriptTag = node.children.find(function(child) {
|
||||
return child.openingElement && child.openingElement.name && child.openingElement.name.name === 'Script';
|
||||
});
|
||||
if (scriptTag) {
|
||||
context.report({
|
||||
node: node,
|
||||
message: "`next/script` should not be used in `next/head` component. Move `<Script />` outside of `<Head>` instead. See: ".concat(url)
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _definerule = require("../utils/define-rule");
|
||||
var _path = /*#__PURE__*/ _interop_require_wildcard(require("path"));
|
||||
function _getRequireWildcardCache(nodeInterop) {
|
||||
if (typeof WeakMap !== "function") return null;
|
||||
var cacheBabelInterop = new WeakMap();
|
||||
var cacheNodeInterop = new WeakMap();
|
||||
return (_getRequireWildcardCache = function(nodeInterop) {
|
||||
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
||||
})(nodeInterop);
|
||||
}
|
||||
function _interop_require_wildcard(obj, nodeInterop) {
|
||||
if (!nodeInterop && obj && obj.__esModule) {
|
||||
return obj;
|
||||
}
|
||||
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
||||
return {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
var cache = _getRequireWildcardCache(nodeInterop);
|
||||
if (cache && cache.has(obj)) {
|
||||
return cache.get(obj);
|
||||
}
|
||||
var newObj = {
|
||||
__proto__: null
|
||||
};
|
||||
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
||||
for(var key in obj){
|
||||
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
||||
if (desc && (desc.get || desc.set)) {
|
||||
Object.defineProperty(newObj, key, desc);
|
||||
} else {
|
||||
newObj[key] = obj[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
newObj.default = obj;
|
||||
if (cache) {
|
||||
cache.set(obj, newObj);
|
||||
}
|
||||
return newObj;
|
||||
}
|
||||
var url = 'https://nextjs.org/docs/messages/no-styled-jsx-in-document';
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Prevent usage of `styled-jsx` in `pages/_document.js`.',
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
return {
|
||||
JSXOpeningElement: function JSXOpeningElement(node) {
|
||||
var document = context.filename.split('pages', 2)[1];
|
||||
if (!document) {
|
||||
return;
|
||||
}
|
||||
var _path_parse = _path.parse(document), name = _path_parse.name, dir = _path_parse.dir;
|
||||
if (!(name.startsWith('_document') || dir === '/_document' && name === 'index')) {
|
||||
return;
|
||||
}
|
||||
if (node.name.name === 'style' && node.attributes.find(function(attr) {
|
||||
return attr.type === 'JSXAttribute' && attr.name.name === 'jsx';
|
||||
})) {
|
||||
context.report({
|
||||
node: node,
|
||||
message: "`styled-jsx` should not be used in `pages/_document.js`. See: ".concat(url)
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _definerule = require("../utils/define-rule");
|
||||
var url = 'https://nextjs.org/docs/messages/no-sync-scripts';
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Prevent synchronous scripts.',
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
return {
|
||||
JSXOpeningElement: function JSXOpeningElement(node) {
|
||||
if (node.name.name !== 'script') {
|
||||
return;
|
||||
}
|
||||
if (node.attributes.length === 0) {
|
||||
return;
|
||||
}
|
||||
var attributeNames = node.attributes.filter(function(attr) {
|
||||
return attr.type === 'JSXAttribute';
|
||||
}).map(function(attr) {
|
||||
return attr.name.name;
|
||||
});
|
||||
if (attributeNames.includes('src') && !attributeNames.includes('async') && !attributeNames.includes('defer')) {
|
||||
context.report({
|
||||
node: node,
|
||||
message: "Synchronous scripts should not be used. See: ".concat(url)
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _definerule = require("../utils/define-rule");
|
||||
var url = 'https://nextjs.org/docs/messages/no-title-in-document-head';
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Prevent usage of `<title>` with `Head` component from `next/document`.',
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
var headFromNextDocument = false;
|
||||
return {
|
||||
ImportDeclaration: function ImportDeclaration(node) {
|
||||
if (node.source.value === 'next/document') {
|
||||
if (node.specifiers.some(function(param) {
|
||||
var local = param.local;
|
||||
return local.name === 'Head';
|
||||
})) {
|
||||
headFromNextDocument = true;
|
||||
}
|
||||
}
|
||||
},
|
||||
JSXElement: function JSXElement(node) {
|
||||
if (!headFromNextDocument) {
|
||||
return;
|
||||
}
|
||||
if (node.openingElement && node.openingElement.name && node.openingElement.name.name !== 'Head') {
|
||||
return;
|
||||
}
|
||||
var titleTag = node.children.find(function(child) {
|
||||
return child.openingElement && child.openingElement.name && child.openingElement.name.type === 'JSXIdentifier' && child.openingElement.name.name === 'title';
|
||||
});
|
||||
if (titleTag) {
|
||||
context.report({
|
||||
node: titleTag,
|
||||
message: "Do not use `<title>` element with `<Head />` component from `next/document`. Titles should defined at the page-level using `<Head />` from `next/head` instead. See: ".concat(url)
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _definerule = require("../utils/define-rule");
|
||||
var _path = /*#__PURE__*/ _interop_require_wildcard(require("path"));
|
||||
function _getRequireWildcardCache(nodeInterop) {
|
||||
if (typeof WeakMap !== "function") return null;
|
||||
var cacheBabelInterop = new WeakMap();
|
||||
var cacheNodeInterop = new WeakMap();
|
||||
return (_getRequireWildcardCache = function(nodeInterop) {
|
||||
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
||||
})(nodeInterop);
|
||||
}
|
||||
function _interop_require_wildcard(obj, nodeInterop) {
|
||||
if (!nodeInterop && obj && obj.__esModule) {
|
||||
return obj;
|
||||
}
|
||||
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
||||
return {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
var cache = _getRequireWildcardCache(nodeInterop);
|
||||
if (cache && cache.has(obj)) {
|
||||
return cache.get(obj);
|
||||
}
|
||||
var newObj = {
|
||||
__proto__: null
|
||||
};
|
||||
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
||||
for(var key in obj){
|
||||
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
||||
if (desc && (desc.get || desc.set)) {
|
||||
Object.defineProperty(newObj, key, desc);
|
||||
} else {
|
||||
newObj[key] = obj[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
newObj.default = obj;
|
||||
if (cache) {
|
||||
cache.set(obj, newObj);
|
||||
}
|
||||
return newObj;
|
||||
}
|
||||
var NEXT_EXPORT_FUNCTIONS = [
|
||||
'getStaticProps',
|
||||
'getStaticPaths',
|
||||
'getServerSideProps'
|
||||
];
|
||||
// 0 is the exact match
|
||||
var THRESHOLD = 1;
|
||||
// the minimum number of operations required to convert string a to string b.
|
||||
function minDistance(a, b) {
|
||||
var m = a.length;
|
||||
var n = b.length;
|
||||
if (m < n) {
|
||||
return minDistance(b, a);
|
||||
}
|
||||
if (n === 0) {
|
||||
return m;
|
||||
}
|
||||
var previousRow = Array.from({
|
||||
length: n + 1
|
||||
}, function(_, i) {
|
||||
return i;
|
||||
});
|
||||
for(var i = 0; i < m; i++){
|
||||
var s1 = a[i];
|
||||
var currentRow = [
|
||||
i + 1
|
||||
];
|
||||
for(var j = 0; j < n; j++){
|
||||
var s2 = b[j];
|
||||
var insertions = previousRow[j + 1] + 1;
|
||||
var deletions = currentRow[j] + 1;
|
||||
var substitutions = previousRow[j] + Number(s1 !== s2);
|
||||
currentRow.push(Math.min(insertions, deletions, substitutions));
|
||||
}
|
||||
previousRow = currentRow;
|
||||
}
|
||||
return previousRow[previousRow.length - 1];
|
||||
}
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Prevent common typos in Next.js data fetching functions.',
|
||||
recommended: true
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
function checkTypos(node, name) {
|
||||
if (NEXT_EXPORT_FUNCTIONS.includes(name)) {
|
||||
return;
|
||||
}
|
||||
var potentialTypos = NEXT_EXPORT_FUNCTIONS.map(function(o) {
|
||||
return {
|
||||
option: o,
|
||||
distance: minDistance(o, name)
|
||||
};
|
||||
}).filter(function(param) {
|
||||
var distance = param.distance;
|
||||
return distance <= THRESHOLD && distance > 0;
|
||||
}).sort(function(a, b) {
|
||||
return a.distance - b.distance;
|
||||
});
|
||||
if (potentialTypos.length) {
|
||||
context.report({
|
||||
node: node,
|
||||
message: "".concat(name, " may be a typo. Did you mean ").concat(potentialTypos[0].option, "?")
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
ExportNamedDeclaration: function ExportNamedDeclaration(node) {
|
||||
var page = context.filename.split('pages', 2)[1];
|
||||
if (!page || _path.parse(page).dir.startsWith('/api')) {
|
||||
return;
|
||||
}
|
||||
var decl = node.declaration;
|
||||
if (!decl) {
|
||||
return;
|
||||
}
|
||||
switch(decl.type){
|
||||
case 'FunctionDeclaration':
|
||||
{
|
||||
checkTypos(node, decl.id.name);
|
||||
break;
|
||||
}
|
||||
case 'VariableDeclaration':
|
||||
{
|
||||
decl.declarations.forEach(function(d) {
|
||||
if (d.id.type !== 'Identifier') {
|
||||
return;
|
||||
}
|
||||
checkTypos(node, d.id.name);
|
||||
});
|
||||
break;
|
||||
}
|
||||
case 'ClassDeclaration':
|
||||
break;
|
||||
default:
|
||||
decl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
declare const _default: import("eslint").Rule.RuleModule;
|
||||
export default _default;
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, //------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
"default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return _default;
|
||||
}
|
||||
});
|
||||
var _definerule = require("../utils/define-rule");
|
||||
// Keep in sync with next.js polyfills file : https://github.com/vercel/next.js/blob/master/packages/next-polyfill-nomodule/src/index.js
|
||||
var NEXT_POLYFILLED_FEATURES = [
|
||||
'Array.prototype.@@iterator',
|
||||
'Array.prototype.at',
|
||||
'Array.prototype.copyWithin',
|
||||
'Array.prototype.fill',
|
||||
'Array.prototype.find',
|
||||
'Array.prototype.findIndex',
|
||||
'Array.prototype.flatMap',
|
||||
'Array.prototype.flat',
|
||||
'Array.from',
|
||||
'Array.prototype.includes',
|
||||
'Array.of',
|
||||
'Function.prototype.name',
|
||||
'fetch',
|
||||
'Map',
|
||||
'Number.EPSILON',
|
||||
'Number.Epsilon',
|
||||
'Number.isFinite',
|
||||
'Number.isNaN',
|
||||
'Number.isInteger',
|
||||
'Number.isSafeInteger',
|
||||
'Number.MAX_SAFE_INTEGER',
|
||||
'Number.MIN_SAFE_INTEGER',
|
||||
'Number.parseFloat',
|
||||
'Number.parseInt',
|
||||
'Object.assign',
|
||||
'Object.entries',
|
||||
'Object.fromEntries',
|
||||
'Object.getOwnPropertyDescriptor',
|
||||
'Object.getOwnPropertyDescriptors',
|
||||
'Object.hasOwn',
|
||||
'Object.is',
|
||||
'Object.keys',
|
||||
'Object.values',
|
||||
'Reflect',
|
||||
'Set',
|
||||
'Symbol',
|
||||
'Symbol.asyncIterator',
|
||||
'String.prototype.codePointAt',
|
||||
'String.prototype.endsWith',
|
||||
'String.fromCodePoint',
|
||||
'String.prototype.includes',
|
||||
'String.prototype.@@iterator',
|
||||
'String.prototype.padEnd',
|
||||
'String.prototype.padStart',
|
||||
'String.prototype.repeat',
|
||||
'String.raw',
|
||||
'String.prototype.startsWith',
|
||||
'String.prototype.trimEnd',
|
||||
'String.prototype.trimStart',
|
||||
'URL',
|
||||
'URL.prototype.toJSON',
|
||||
'URLSearchParams',
|
||||
'WeakMap',
|
||||
'WeakSet',
|
||||
'Promise',
|
||||
'Promise.prototype.finally',
|
||||
'es2015',
|
||||
'es2016',
|
||||
'es2017',
|
||||
'es2018',
|
||||
'es2019',
|
||||
'es5',
|
||||
'es6',
|
||||
'es7'
|
||||
];
|
||||
var url = 'https://nextjs.org/docs/messages/no-unwanted-polyfillio';
|
||||
var _default = (0, _definerule.defineRule)({
|
||||
meta: {
|
||||
docs: {
|
||||
description: 'Prevent duplicate polyfills from Polyfill.io.',
|
||||
category: 'HTML',
|
||||
recommended: true,
|
||||
url: url
|
||||
},
|
||||
type: 'problem',
|
||||
schema: []
|
||||
},
|
||||
create: function create(context) {
|
||||
var scriptImport = null;
|
||||
return {
|
||||
ImportDeclaration: function ImportDeclaration(node) {
|
||||
if (node.source && node.source.value === 'next/script') {
|
||||
scriptImport = node.specifiers[0].local.name;
|
||||
}
|
||||
},
|
||||
JSXOpeningElement: function JSXOpeningElement(node) {
|
||||
if (node.name && node.name.name !== 'script' && node.name.name !== scriptImport) {
|
||||
return;
|
||||
}
|
||||
if (node.attributes.length === 0) {
|
||||
return;
|
||||
}
|
||||
var srcNode = node.attributes.find(function(attr) {
|
||||
return attr.type === 'JSXAttribute' && attr.name.name === 'src';
|
||||
});
|
||||
if (!srcNode || srcNode.value.type !== 'Literal') {
|
||||
return;
|
||||
}
|
||||
var src = srcNode.value.value;
|
||||
if (src.startsWith('https://cdn.polyfill.io/v2/') || src.startsWith('https://polyfill.io/v3/') || // https://community.fastly.com/t/new-options-for-polyfill-io-users/2540
|
||||
src.startsWith('https://polyfill-fastly.net/') || src.startsWith('https://polyfill-fastly.io/') || // https://blog.cloudflare.com/polyfill-io-now-available-on-cdnjs-reduce-your-supply-chain-risk
|
||||
src.startsWith('https://cdnjs.cloudflare.com/polyfill/')) {
|
||||
var featureQueryString = new URL(src).searchParams.get('features');
|
||||
var featuresRequested = (featureQueryString || '').split(',');
|
||||
var unwantedFeatures = featuresRequested.filter(function(feature) {
|
||||
return NEXT_POLYFILLED_FEATURES.includes(feature);
|
||||
});
|
||||
if (unwantedFeatures.length > 0) {
|
||||
context.report({
|
||||
node: node,
|
||||
message: "No duplicate polyfills from Polyfill.io are allowed. ".concat(unwantedFeatures.join(', '), " ").concat(unwantedFeatures.length > 1 ? 'are' : 'is', " already shipped with Next.js. See: ").concat(url)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
import type { Rule } from 'eslint';
|
||||
export declare const defineRule: (rule: Rule.RuleModule) => Rule.RuleModule;
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "defineRule", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return defineRule;
|
||||
}
|
||||
});
|
||||
var defineRule = function(rule) {
|
||||
return rule;
|
||||
};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import type { Rule } from 'eslint';
|
||||
/**
|
||||
* Gets one or more Root, returns an array of root directories.
|
||||
*/
|
||||
export declare const getRootDirs: (context: Rule.RuleContext) => string[];
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "getRootDirs", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return getRootDirs;
|
||||
}
|
||||
});
|
||||
var _fastglob = require("fast-glob");
|
||||
/**
|
||||
* Process a Next.js root directory glob.
|
||||
*/ var processRootDir = function(rootDir) {
|
||||
return (0, _fastglob.globSync)(rootDir.replace(/\\/g, '/'), {
|
||||
onlyDirectories: true
|
||||
});
|
||||
};
|
||||
var getRootDirs = function(context) {
|
||||
var rootDirs = [
|
||||
context.cwd
|
||||
];
|
||||
var nextSettings = context.settings.next || {};
|
||||
var rootDir = nextSettings.rootDir;
|
||||
if (typeof rootDir === 'string') {
|
||||
rootDirs = processRootDir(rootDir);
|
||||
} else if (Array.isArray(rootDir)) {
|
||||
rootDirs = rootDir.map(function(dir) {
|
||||
return typeof dir === 'string' ? processRootDir(dir) : [];
|
||||
}).flat();
|
||||
}
|
||||
return rootDirs;
|
||||
};
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
export default class NodeAttributes {
|
||||
attributes: Record<string, {
|
||||
hasValue?: false;
|
||||
} | {
|
||||
hasValue: true;
|
||||
value: any;
|
||||
}>;
|
||||
constructor(ASTnode: any);
|
||||
hasAny(): boolean;
|
||||
has(attrName: string): boolean;
|
||||
hasValue(attrName: string): boolean;
|
||||
value(attrName: string): any;
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
// Return attributes and values of a node in a convenient way:
|
||||
/* example:
|
||||
<ExampleElement attr1="15" attr2>
|
||||
{ attr1: {
|
||||
hasValue: true,
|
||||
value: 15
|
||||
},
|
||||
attr2: {
|
||||
hasValue: false
|
||||
}
|
||||
Inclusion of hasValue is in case an eslint rule cares about boolean values
|
||||
explicitly assigned to attribute vs the attribute being used as a flag
|
||||
*/ "use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "default", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return NodeAttributes;
|
||||
}
|
||||
});
|
||||
function _class_call_check(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
function _defineProperties(target, props) {
|
||||
for(var i = 0; i < props.length; i++){
|
||||
var descriptor = props[i];
|
||||
descriptor.enumerable = descriptor.enumerable || false;
|
||||
descriptor.configurable = true;
|
||||
if ("value" in descriptor) descriptor.writable = true;
|
||||
Object.defineProperty(target, descriptor.key, descriptor);
|
||||
}
|
||||
}
|
||||
function _create_class(Constructor, protoProps, staticProps) {
|
||||
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
||||
if (staticProps) _defineProperties(Constructor, staticProps);
|
||||
return Constructor;
|
||||
}
|
||||
function _define_property(obj, key, value) {
|
||||
if (key in obj) {
|
||||
Object.defineProperty(obj, key, {
|
||||
value: value,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: true
|
||||
});
|
||||
} else {
|
||||
obj[key] = value;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
var NodeAttributes = /*#__PURE__*/ function() {
|
||||
"use strict";
|
||||
function NodeAttributes(ASTnode) {
|
||||
var _this = this;
|
||||
_class_call_check(this, NodeAttributes);
|
||||
_define_property(this, "attributes", void 0);
|
||||
this.attributes = {};
|
||||
ASTnode.attributes.forEach(function(attribute) {
|
||||
if (!attribute.type || attribute.type !== 'JSXAttribute') {
|
||||
return;
|
||||
}
|
||||
if (!!attribute.value) {
|
||||
// hasValue
|
||||
var value = typeof attribute.value.value === 'string' ? attribute.value.value : typeof attribute.value.expression.value !== 'undefined' ? attribute.value.expression.value : attribute.value.expression.properties;
|
||||
_this.attributes[attribute.name.name] = {
|
||||
hasValue: true,
|
||||
value: value
|
||||
};
|
||||
} else {
|
||||
_this.attributes[attribute.name.name] = {
|
||||
hasValue: false
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
_create_class(NodeAttributes, [
|
||||
{
|
||||
key: "hasAny",
|
||||
value: function hasAny() {
|
||||
return !!Object.keys(this.attributes).length;
|
||||
}
|
||||
},
|
||||
{
|
||||
key: "has",
|
||||
value: function has(attrName) {
|
||||
return !!this.attributes[attrName];
|
||||
}
|
||||
},
|
||||
{
|
||||
key: "hasValue",
|
||||
value: function hasValue(attrName) {
|
||||
return !!this.attributes[attrName].hasValue;
|
||||
}
|
||||
},
|
||||
{
|
||||
key: "value",
|
||||
value: function value(attrName) {
|
||||
var attr = this.attributes[attrName];
|
||||
if (!attr) {
|
||||
return true;
|
||||
}
|
||||
if (attr.hasValue) {
|
||||
return attr.value;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
]);
|
||||
return NodeAttributes;
|
||||
}();
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Takes a URL and does the following things.
|
||||
* - Replaces `index.html` with `/`
|
||||
* - Makes sure all URLs are have a trailing `/`
|
||||
* - Removes query string
|
||||
*/
|
||||
export declare function normalizeURL(url: string): string;
|
||||
/**
|
||||
* Normalizes an app route so it represents the actual request path. Essentially
|
||||
* performing the following transformations:
|
||||
*
|
||||
* - `/(dashboard)/user/[id]/page` to `/user/[id]`
|
||||
* - `/(dashboard)/account/page` to `/account`
|
||||
* - `/user/[id]/page` to `/user/[id]`
|
||||
* - `/account/page` to `/account`
|
||||
* - `/page` to `/`
|
||||
* - `/(dashboard)/user/[id]/route` to `/user/[id]`
|
||||
* - `/(dashboard)/account/route` to `/account`
|
||||
* - `/user/[id]/route` to `/user/[id]`
|
||||
* - `/account/route` to `/account`
|
||||
* - `/route` to `/`
|
||||
* - `/` to `/`
|
||||
*
|
||||
* @param route the app route to normalize
|
||||
* @returns the normalized pathname
|
||||
*/
|
||||
export declare function normalizeAppPath(route: string): string;
|
||||
/**
|
||||
* Gets the possible URLs from a directory.
|
||||
*/
|
||||
export declare function getUrlFromPagesDirectories(urlPrefix: string, directories: string[]): RegExp[];
|
||||
export declare function getUrlFromAppDirectory(urlPrefix: string, directories: string[]): RegExp[];
|
||||
export declare function execOnce<TArgs extends any[], TResult>(fn: (...args: TArgs) => TResult): (...args: TArgs) => TResult;
|
||||
+232
@@ -0,0 +1,232 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
function _export(target, all) {
|
||||
for(var name in all)Object.defineProperty(target, name, {
|
||||
enumerable: true,
|
||||
get: all[name]
|
||||
});
|
||||
}
|
||||
_export(exports, {
|
||||
execOnce: function() {
|
||||
return execOnce;
|
||||
},
|
||||
getUrlFromAppDirectory: function() {
|
||||
return getUrlFromAppDirectory;
|
||||
},
|
||||
getUrlFromPagesDirectories: function() {
|
||||
return getUrlFromPagesDirectories;
|
||||
},
|
||||
normalizeAppPath: function() {
|
||||
return normalizeAppPath;
|
||||
},
|
||||
normalizeURL: function() {
|
||||
return normalizeURL;
|
||||
}
|
||||
});
|
||||
var _path = /*#__PURE__*/ _interop_require_wildcard(require("path"));
|
||||
var _fs = /*#__PURE__*/ _interop_require_wildcard(require("fs"));
|
||||
function _array_like_to_array(arr, len) {
|
||||
if (len == null || len > arr.length) len = arr.length;
|
||||
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
||||
return arr2;
|
||||
}
|
||||
function _array_without_holes(arr) {
|
||||
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
||||
}
|
||||
function _getRequireWildcardCache(nodeInterop) {
|
||||
if (typeof WeakMap !== "function") return null;
|
||||
var cacheBabelInterop = new WeakMap();
|
||||
var cacheNodeInterop = new WeakMap();
|
||||
return (_getRequireWildcardCache = function(nodeInterop) {
|
||||
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
||||
})(nodeInterop);
|
||||
}
|
||||
function _interop_require_wildcard(obj, nodeInterop) {
|
||||
if (!nodeInterop && obj && obj.__esModule) {
|
||||
return obj;
|
||||
}
|
||||
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
||||
return {
|
||||
default: obj
|
||||
};
|
||||
}
|
||||
var cache = _getRequireWildcardCache(nodeInterop);
|
||||
if (cache && cache.has(obj)) {
|
||||
return cache.get(obj);
|
||||
}
|
||||
var newObj = {
|
||||
__proto__: null
|
||||
};
|
||||
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
||||
for(var key in obj){
|
||||
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
||||
if (desc && (desc.get || desc.set)) {
|
||||
Object.defineProperty(newObj, key, desc);
|
||||
} else {
|
||||
newObj[key] = obj[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
newObj.default = obj;
|
||||
if (cache) {
|
||||
cache.set(obj, newObj);
|
||||
}
|
||||
return newObj;
|
||||
}
|
||||
function _iterable_to_array(iter) {
|
||||
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
||||
}
|
||||
function _non_iterable_spread() {
|
||||
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
||||
}
|
||||
function _to_consumable_array(arr) {
|
||||
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
||||
}
|
||||
function _unsupported_iterable_to_array(o, minLen) {
|
||||
if (!o) return;
|
||||
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
||||
var n = Object.prototype.toString.call(o).slice(8, -1);
|
||||
if (n === "Object" && o.constructor) n = o.constructor.name;
|
||||
if (n === "Map" || n === "Set") return Array.from(n);
|
||||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
||||
}
|
||||
// Cache for fs.readdirSync lookup.
|
||||
// Prevent multiple blocking IO requests that have already been calculated.
|
||||
var fsReadDirSyncCache = {};
|
||||
/**
|
||||
* Recursively parse directory for page URLs.
|
||||
*/ function parseUrlForPages(urlprefix, directory) {
|
||||
var _fsReadDirSyncCache, _directory;
|
||||
var _;
|
||||
(_ = (_fsReadDirSyncCache = fsReadDirSyncCache)[_directory = directory]) !== null && _ !== void 0 ? _ : _fsReadDirSyncCache[_directory] = _fs.readdirSync(directory, {
|
||||
withFileTypes: true
|
||||
});
|
||||
var res = [];
|
||||
fsReadDirSyncCache[directory].forEach(function(dirent) {
|
||||
// TODO: this should account for all page extensions
|
||||
// not just js(x) and ts(x)
|
||||
if (/(\.(j|t)sx?)$/.test(dirent.name)) {
|
||||
if (/^index(\.(j|t)sx?)$/.test(dirent.name)) {
|
||||
res.push("".concat(urlprefix).concat(dirent.name.replace(/^index(\.(j|t)sx?)$/, '')));
|
||||
}
|
||||
res.push("".concat(urlprefix).concat(dirent.name.replace(/(\.(j|t)sx?)$/, '')));
|
||||
} else {
|
||||
var dirPath = _path.join(directory, dirent.name);
|
||||
if (dirent.isDirectory() && !dirent.isSymbolicLink()) {
|
||||
var _res;
|
||||
(_res = res).push.apply(_res, _to_consumable_array(parseUrlForPages(urlprefix + dirent.name + '/', dirPath)));
|
||||
}
|
||||
}
|
||||
});
|
||||
return res;
|
||||
}
|
||||
/**
|
||||
* Recursively parse app directory for URLs.
|
||||
*/ function parseUrlForAppDir(urlprefix, directory) {
|
||||
var _fsReadDirSyncCache, _directory;
|
||||
var _;
|
||||
(_ = (_fsReadDirSyncCache = fsReadDirSyncCache)[_directory = directory]) !== null && _ !== void 0 ? _ : _fsReadDirSyncCache[_directory] = _fs.readdirSync(directory, {
|
||||
withFileTypes: true
|
||||
});
|
||||
var res = [];
|
||||
fsReadDirSyncCache[directory].forEach(function(dirent) {
|
||||
// TODO: this should account for all page extensions
|
||||
// not just js(x) and ts(x)
|
||||
if (/(\.(j|t)sx?)$/.test(dirent.name)) {
|
||||
if (/^page(\.(j|t)sx?)$/.test(dirent.name)) {
|
||||
res.push("".concat(urlprefix).concat(dirent.name.replace(/^page(\.(j|t)sx?)$/, '')));
|
||||
} else if (!/^layout(\.(j|t)sx?)$/.test(dirent.name)) {
|
||||
res.push("".concat(urlprefix).concat(dirent.name.replace(/(\.(j|t)sx?)$/, '')));
|
||||
}
|
||||
} else {
|
||||
var dirPath = _path.join(directory, dirent.name);
|
||||
if (dirent.isDirectory(dirPath) && !dirent.isSymbolicLink()) {
|
||||
var _res;
|
||||
(_res = res).push.apply(_res, _to_consumable_array(parseUrlForPages(urlprefix + dirent.name + '/', dirPath)));
|
||||
}
|
||||
}
|
||||
});
|
||||
return res;
|
||||
}
|
||||
function normalizeURL(url) {
|
||||
if (!url) {
|
||||
return;
|
||||
}
|
||||
url = url.split('?', 1)[0];
|
||||
url = url.split('#', 1)[0];
|
||||
url = url = url.replace(/(\/index\.html)$/, '/');
|
||||
// Empty URLs should not be trailed with `/`, e.g. `#heading`
|
||||
if (url === '') {
|
||||
return url;
|
||||
}
|
||||
url = url.endsWith('/') ? url : url + '/';
|
||||
return url;
|
||||
}
|
||||
function normalizeAppPath(route) {
|
||||
return ensureLeadingSlash(route.split('/').reduce(function(pathname, segment, index, segments) {
|
||||
// Empty segments are ignored.
|
||||
if (!segment) {
|
||||
return pathname;
|
||||
}
|
||||
// Groups are ignored.
|
||||
if (isGroupSegment(segment)) {
|
||||
return pathname;
|
||||
}
|
||||
// Parallel segments are ignored.
|
||||
if (segment[0] === '@') {
|
||||
return pathname;
|
||||
}
|
||||
// The last segment (if it's a leaf) should be ignored.
|
||||
if ((segment === 'page' || segment === 'route') && index === segments.length - 1) {
|
||||
return pathname;
|
||||
}
|
||||
return "".concat(pathname, "/").concat(segment);
|
||||
}, ''));
|
||||
}
|
||||
function getUrlFromPagesDirectories(urlPrefix, directories) {
|
||||
return Array.from(// De-duplicate similar pages across multiple directories.
|
||||
new Set(directories.flatMap(function(directory) {
|
||||
return parseUrlForPages(urlPrefix, directory);
|
||||
}).map(// Since the URLs are normalized we add `^` and `$` to the RegExp to make sure they match exactly.
|
||||
function(url) {
|
||||
return "^".concat(normalizeURL(url), "$");
|
||||
}))).map(function(urlReg) {
|
||||
urlReg = urlReg.replace(/\[.*\]/g, '((?!.+?\\..+?).*?)');
|
||||
return new RegExp(urlReg);
|
||||
});
|
||||
}
|
||||
function getUrlFromAppDirectory(urlPrefix, directories) {
|
||||
return Array.from(// De-duplicate similar pages across multiple directories.
|
||||
new Set(directories.map(function(directory) {
|
||||
return parseUrlForAppDir(urlPrefix, directory);
|
||||
}).flat().map(// Since the URLs are normalized we add `^` and `$` to the RegExp to make sure they match exactly.
|
||||
function(url) {
|
||||
return "^".concat(normalizeAppPath(url), "$");
|
||||
}))).map(function(urlReg) {
|
||||
urlReg = urlReg.replace(/\[.*\]/g, '((?!.+?\\..+?).*?)');
|
||||
return new RegExp(urlReg);
|
||||
});
|
||||
}
|
||||
function execOnce(fn) {
|
||||
var used = false;
|
||||
var result;
|
||||
return function() {
|
||||
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
if (!used) {
|
||||
used = true;
|
||||
result = fn.apply(void 0, _to_consumable_array(args));
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
function ensureLeadingSlash(route) {
|
||||
return route.startsWith('/') ? route : "/".concat(route);
|
||||
}
|
||||
function isGroupSegment(segment) {
|
||||
return segment[0] === '(' && segment.endsWith(')');
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "@next/eslint-plugin-next",
|
||||
"version": "16.1.6",
|
||||
"description": "ESLint plugin for Next.js.",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"url": "vercel/next.js",
|
||||
"directory": "packages/eslint-plugin-next"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"dependencies": {
|
||||
"fast-glob": "3.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/eslint": "9.6.1",
|
||||
"eslint": "9.37.0"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "pnpm build",
|
||||
"build": "swc -d dist src && pnpm types",
|
||||
"types": "tsc src/index.ts --skipLibCheck --declaration --emitDeclarationOnly --esModuleInterop --declarationDir dist",
|
||||
"prepublishOnly": "cd ../../ && turbo run build"
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
# `@next/swc-darwin-arm64`
|
||||
|
||||
This is the **aarch64-apple-darwin** binary for `@next/swc`
|
||||
BIN
Binary file not shown.
+23
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "@next/swc-darwin-arm64",
|
||||
"version": "16.1.6",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/vercel/next.js",
|
||||
"directory": "crates/napi/npm/darwin-arm64"
|
||||
},
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"main": "next-swc.darwin-arm64.node",
|
||||
"files": [
|
||||
"next-swc.darwin-arm64.node"
|
||||
],
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 10"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user