@next/eslint-plugin-next 16.0.2 → 16.1.0-canary.0

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.
@@ -15,23 +15,14 @@ function _interop_require_default(obj) {
15
15
  default: obj
16
16
  };
17
17
  }
18
- var SUPPORTED_SRCS = [
19
- 'www.google-analytics.com/analytics.js',
20
- 'www.googletagmanager.com/gtag/js'
21
- ];
22
- var SUPPORTED_HTML_CONTENT_URLS = [
23
- 'www.google-analytics.com/analytics.js',
24
- 'www.googletagmanager.com/gtm.js'
25
- ];
26
- var description = 'Prefer `next/script` component when using the inline script for Google Analytics.';
18
+ var GOOGLE_ANALYTICS_URL = 'www.google-analytics.com/analytics.js';
19
+ var GOOGLE_TAG_MANAGER_URL = 'www.googletagmanager.com/gtag/js';
20
+ var GOOGLE_ANALYTICS_SRC = GOOGLE_ANALYTICS_URL;
21
+ var GOOGLE_TAG_MANAGER_SRC = 'www.googletagmanager.com/gtm.js';
22
+ var description = 'Prefer `@next/third-parties/google` when using the inline script for Google Analytics and Tag Manager.';
27
23
  var url = 'https://nextjs.org/docs/messages/next-script-for-ga';
28
- var ERROR_MSG = "".concat(description, " See: ").concat(url);
29
- // Check if one of the items in the list is a substring of the passed string
30
- var containsStr = function(str, strList) {
31
- return strList.some(function(s) {
32
- return str.includes(s);
33
- });
34
- };
24
+ var ERROR_MSG_GOOGLE_ANALYTICS = "Prefer `GoogleAnalytics` component from `@next/third-parties/google` when using the inline script for Google Analytics. See: ".concat(url);
25
+ 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);
35
26
  var _default = (0, _definerule.defineRule)({
36
27
  meta: {
37
28
  docs: {
@@ -52,24 +43,38 @@ var _default = (0, _definerule.defineRule)({
52
43
  return;
53
44
  }
54
45
  var attributes = new _nodeattributes.default(node);
46
+ var src = attributes.value('src');
55
47
  // Check if the Alternative async tag is being used to add GA.
56
48
  // https://developers.google.com/analytics/devguides/collection/analyticsjs#alternative_async_tag
57
49
  // https://developers.google.com/analytics/devguides/collection/gtagjs
58
- if (typeof attributes.value('src') === 'string' && containsStr(attributes.value('src'), SUPPORTED_SRCS)) {
50
+ if (typeof src === 'string' && src.includes(GOOGLE_ANALYTICS_URL)) {
59
51
  return context.report({
60
52
  node: node,
61
- message: ERROR_MSG
53
+ message: ERROR_MSG_GOOGLE_ANALYTICS
54
+ });
55
+ } else if (typeof src === 'string' && src.includes(GOOGLE_TAG_MANAGER_URL)) {
56
+ return context.report({
57
+ node: node,
58
+ message: ERROR_MSG_GOOGLE_TAG_MANAGER
62
59
  });
63
60
  }
61
+ var dangerouslySetInnerHTML = attributes.value('dangerouslySetInnerHTML');
64
62
  // Check if inline script is being used to add GA.
65
63
  // https://developers.google.com/analytics/devguides/collection/analyticsjs#the_google_analytics_tag
66
64
  // https://developers.google.com/tag-manager/quickstart
67
- if (attributes.value('dangerouslySetInnerHTML') && attributes.value('dangerouslySetInnerHTML').length > 0) {
68
- var htmlContent = attributes.value('dangerouslySetInnerHTML')[0].value.quasis && attributes.value('dangerouslySetInnerHTML')[0].value.quasis[0].value.raw;
69
- if (htmlContent && containsStr(htmlContent, SUPPORTED_HTML_CONTENT_URLS)) {
65
+ if (dangerouslySetInnerHTML && dangerouslySetInnerHTML.length > 0) {
66
+ var _quasis__value, _quasis_;
67
+ var quasis = dangerouslySetInnerHTML[0].value.quasis;
68
+ 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;
69
+ if (htmlContent && htmlContent.includes(GOOGLE_ANALYTICS_SRC)) {
70
+ context.report({
71
+ node: node,
72
+ message: ERROR_MSG_GOOGLE_ANALYTICS
73
+ });
74
+ } else if (htmlContent && htmlContent.includes(GOOGLE_TAG_MANAGER_SRC)) {
70
75
  context.report({
71
76
  node: node,
72
- message: ERROR_MSG
77
+ message: ERROR_MSG_GOOGLE_TAG_MANAGER
73
78
  });
74
79
  }
75
80
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next/eslint-plugin-next",
3
- "version": "16.0.2",
3
+ "version": "16.1.0-canary.0",
4
4
  "description": "ESLint plugin for Next.js.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",