@next/eslint-plugin-next 15.2.0-canary.2 → 15.2.0-canary.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -109,6 +109,21 @@ var pagesDirWarning = (0, _url.execOnce)(function(pagesDirs) {
|
|
|
109
109
|
// Cache for fs.existsSync lookup.
|
|
110
110
|
// Prevent multiple blocking IO requests that have already been calculated.
|
|
111
111
|
var fsExistsSyncCache = {};
|
|
112
|
+
var memoize = function(fn) {
|
|
113
|
+
var cache = {};
|
|
114
|
+
return function() {
|
|
115
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
116
|
+
args[_key] = arguments[_key];
|
|
117
|
+
}
|
|
118
|
+
var key = JSON.stringify(args);
|
|
119
|
+
if (cache[key] === undefined) {
|
|
120
|
+
cache[key] = fn.apply(void 0, _to_consumable_array(args));
|
|
121
|
+
}
|
|
122
|
+
return cache[key];
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
var cachedGetUrlFromPagesDirectories = memoize(_url.getUrlFromPagesDirectories);
|
|
126
|
+
var cachedGetUrlFromAppDirectory = memoize(_url.getUrlFromAppDirectory);
|
|
112
127
|
var url = 'https://nextjs.org/docs/messages/no-html-link-for-pages';
|
|
113
128
|
module.exports = (0, _definerule.defineRule)({
|
|
114
129
|
meta: {
|
|
@@ -173,9 +188,9 @@ module.exports = (0, _definerule.defineRule)({
|
|
|
173
188
|
pagesDirWarning(pagesDirs);
|
|
174
189
|
return {};
|
|
175
190
|
}
|
|
176
|
-
var pageUrls = (
|
|
177
|
-
var appDirUrls = (
|
|
178
|
-
var
|
|
191
|
+
var pageUrls = cachedGetUrlFromPagesDirectories('/', foundPagesDirs);
|
|
192
|
+
var appDirUrls = cachedGetUrlFromAppDirectory('/', foundAppDirs);
|
|
193
|
+
var allUrlRegex = _to_consumable_array(pageUrls).concat(_to_consumable_array(appDirUrls));
|
|
179
194
|
return {
|
|
180
195
|
JSXOpeningElement: function JSXOpeningElement(node) {
|
|
181
196
|
if (node.name.name !== 'a') {
|
|
@@ -207,7 +222,7 @@ module.exports = (0, _definerule.defineRule)({
|
|
|
207
222
|
if (/^(https?:\/\/|\/\/)/.test(hrefPath)) {
|
|
208
223
|
return;
|
|
209
224
|
}
|
|
210
|
-
|
|
225
|
+
allUrlRegex.forEach(function(foundUrl) {
|
|
211
226
|
if (foundUrl.test((0, _url.normalizeURL)(hrefPath))) {
|
|
212
227
|
context.report({
|
|
213
228
|
node: node,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _definerule = require("../utils/define-rule");
|
|
3
|
+
var path = require("path");
|
|
3
4
|
var url = 'https://nextjs.org/docs/messages/no-img-element';
|
|
4
5
|
module.exports = (0, _definerule.defineRule)({
|
|
5
6
|
meta: {
|
|
@@ -13,6 +14,9 @@ module.exports = (0, _definerule.defineRule)({
|
|
|
13
14
|
schema: []
|
|
14
15
|
},
|
|
15
16
|
create: function create(context) {
|
|
17
|
+
// Get relative path of the file
|
|
18
|
+
var relativePath = context.filename.replace(path.sep, '/').replace(context.cwd, '').replace(/^\//, '');
|
|
19
|
+
var isAppDir = /^(src\/)?app\//.test(relativePath);
|
|
16
20
|
return {
|
|
17
21
|
JSXOpeningElement: function JSXOpeningElement(node) {
|
|
18
22
|
var _node_parent_parent_openingElement_name, _node_parent_parent_openingElement, _node_parent_parent, _node_parent;
|
|
@@ -25,6 +29,9 @@ module.exports = (0, _definerule.defineRule)({
|
|
|
25
29
|
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') {
|
|
26
30
|
return;
|
|
27
31
|
}
|
|
32
|
+
// If is metadata route files, ignore
|
|
33
|
+
// e.g. opengraph-image.js, twitter-image.js, icon.js
|
|
34
|
+
if (isAppDir && /\/opengraph-image|twitter-image|icon\.\w+$/.test(relativePath)) return;
|
|
28
35
|
context.report({
|
|
29
36
|
node: node,
|
|
30
37
|
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)
|