@akinon/eslint-plugin-projectzero 1.1.1 → 1.3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @akinon/eslint-plugin-projectzero
2
2
 
3
+ ## 1.3.0
4
+
5
+ ## 1.2.0
6
+
7
+ ### Patch Changes
8
+
9
+ - Add skipTrailingSlashRedirect rule.
10
+
3
11
  ## 1.1.1
4
12
 
5
13
  ## 1.1.0
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- # eslint-plugin-projectzero
2
+ # @akinon/eslint-plugin-projectzero
3
3
 
4
4
  ESLint plugin for **Project Zero PWA**.
5
5
  It includes core and recommended rule sets.
@@ -21,10 +21,10 @@ Add the following lines to **.eslintrc.js** file.
21
21
  extends: [
22
22
  ...
23
23
  ...
24
- 'plugin:projectzero/core', // DO NOT remove this config for stability
25
- 'plugin:projectzero/recommended' // Optional
24
+ 'plugin:@akinon/projectzero/core', // DO NOT remove this config for stability
25
+ 'plugin:@akinon/projectzero/recommended' // Optional
26
26
  ],
27
27
  plugins: [
28
28
  ...
29
- 'projectzero'
30
- ]
29
+ '@akinon/projectzero'
30
+ ]
package/configs/core.ts CHANGED
@@ -1,14 +1,16 @@
1
1
  export default {
2
2
  rules: {
3
- 'projectzero/image-import': 'error',
4
- 'projectzero/client-url': 'error',
5
- 'projectzero/link-import': 'error',
6
- 'projectzero/router-import': 'error',
7
- "no-restricted-syntax": [
8
- "error",
3
+ '@akinon/projectzero/image-import': 'error',
4
+ '@akinon/projectzero/client-url': 'error',
5
+ '@akinon/projectzero/link-import': 'error',
6
+ '@akinon/projectzero/router-import': 'error',
7
+ '@akinon/projectzero/skip-trailing-slash-redirect': 'error',
8
+ 'no-restricted-syntax': [
9
+ 'error',
9
10
  {
10
- "selector": "MemberExpression[property.name='COMMERCE_URL'][object.property.name='env'][object.object.name='process']",
11
- "message": "You should use it as 'Settings.commerceUrl'"
11
+ selector:
12
+ "MemberExpression[property.name='COMMERCE_URL'][object.property.name='env'][object.object.name='process']",
13
+ message: "You should use it as 'Settings.commerceUrl'"
12
14
  }
13
15
  ]
14
16
  }
@@ -2,15 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = {
4
4
  rules: {
5
- 'projectzero/image-import': 'error',
6
- 'projectzero/client-url': 'error',
7
- 'projectzero/link-import': 'error',
8
- 'projectzero/router-import': 'error',
9
- "no-restricted-syntax": [
10
- "error",
5
+ '@akinon/projectzero/image-import': 'error',
6
+ '@akinon/projectzero/client-url': 'error',
7
+ '@akinon/projectzero/link-import': 'error',
8
+ '@akinon/projectzero/router-import': 'error',
9
+ '@akinon/projectzero/skip-trailing-slash-redirect': 'error',
10
+ 'no-restricted-syntax': [
11
+ 'error',
11
12
  {
12
- "selector": "MemberExpression[property.name='COMMERCE_URL'][object.property.name='env'][object.object.name='process']",
13
- "message": "You should use it as 'Settings.commerceUrl'"
13
+ selector: "MemberExpression[property.name='COMMERCE_URL'][object.property.name='env'][object.object.name='process']",
14
+ message: "You should use it as 'Settings.commerceUrl'"
14
15
  }
15
16
  ]
16
17
  }
@@ -8,5 +8,12 @@ const client_url_1 = __importDefault(require("./client-url"));
8
8
  const image_import_1 = __importDefault(require("./image-import"));
9
9
  const link_import_1 = __importDefault(require("./link-import"));
10
10
  const router_import_1 = __importDefault(require("./router-import"));
11
- const rules = { 'client-url': client_url_1.default, 'image-import': image_import_1.default, 'link-import': link_import_1.default, 'router-import': router_import_1.default };
11
+ const skip_trailing_slash_redirect_1 = __importDefault(require("./skip-trailing-slash-redirect"));
12
+ const rules = {
13
+ 'client-url': client_url_1.default,
14
+ 'image-import': image_import_1.default,
15
+ 'link-import': link_import_1.default,
16
+ 'router-import': router_import_1.default,
17
+ 'skip-trailing-slash-redirect': skip_trailing_slash_redirect_1.default
18
+ };
12
19
  exports.rules = rules;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const types_1 = require("@typescript-eslint/types");
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
6
+ create(context) {
7
+ return {
8
+ VariableDeclarator(node) {
9
+ var _a;
10
+ if (node.id.type !== types_1.AST_NODE_TYPES.Identifier) {
11
+ return;
12
+ }
13
+ if (node.id.name !== 'nextConfig') {
14
+ return;
15
+ }
16
+ if (((_a = node.init) === null || _a === void 0 ? void 0 : _a.type) !== types_1.AST_NODE_TYPES.ObjectExpression) {
17
+ return;
18
+ }
19
+ const skipTrailingSlashRedirectNode = node.init.properties.find((property) => 'key' in property &&
20
+ property.key.type === types_1.AST_NODE_TYPES.Identifier &&
21
+ property.key.name === 'skipTrailingSlashRedirect');
22
+ if (!skipTrailingSlashRedirectNode ||
23
+ skipTrailingSlashRedirectNode.type !== types_1.AST_NODE_TYPES.Property) {
24
+ return;
25
+ }
26
+ if (skipTrailingSlashRedirectNode.value.type === types_1.AST_NODE_TYPES.Literal &&
27
+ skipTrailingSlashRedirectNode.value.value === true) {
28
+ return;
29
+ }
30
+ context.report({
31
+ node: skipTrailingSlashRedirectNode,
32
+ messageId: 'skipTrailingSlashRedirect',
33
+ fix: (fixer) => fixer.replaceText(skipTrailingSlashRedirectNode.value, 'true')
34
+ });
35
+ }
36
+ };
37
+ },
38
+ meta: {
39
+ messages: {
40
+ skipTrailingSlashRedirect: 'The `skipTrailingSlashRedirect` value must be true.'
41
+ },
42
+ type: 'problem',
43
+ fixable: 'code',
44
+ schema: []
45
+ },
46
+ defaultOptions: []
47
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/eslint-plugin-projectzero",
3
- "version": "1.1.1",
3
+ "version": "1.3.0",
4
4
  "private": false,
5
5
  "description": "ESLint plugin for Project Zero Next",
6
6
  "main": "dist/index.js",
package/rules/index.ts CHANGED
@@ -1,8 +1,15 @@
1
1
  import clientUrl from './client-url';
2
2
  import imageImport from './image-import';
3
3
  import linkImport from './link-import';
4
- import routerImport from './router-import'
4
+ import routerImport from './router-import';
5
+ import skipTrailingSlashRedirect from './skip-trailing-slash-redirect';
5
6
 
6
- const rules = { 'client-url': clientUrl, 'image-import': imageImport, 'link-import': linkImport, 'router-import': routerImport };
7
+ const rules = {
8
+ 'client-url': clientUrl,
9
+ 'image-import': imageImport,
10
+ 'link-import': linkImport,
11
+ 'router-import': routerImport,
12
+ 'skip-trailing-slash-redirect': skipTrailingSlashRedirect
13
+ };
7
14
 
8
15
  export { rules };
@@ -0,0 +1,60 @@
1
+ import { AST_NODE_TYPES } from '@typescript-eslint/types';
2
+ import { ESLintUtils } from '@typescript-eslint/utils';
3
+
4
+ export default ESLintUtils.RuleCreator.withoutDocs({
5
+ create(context) {
6
+ return {
7
+ VariableDeclarator(node) {
8
+ if (node.id.type !== AST_NODE_TYPES.Identifier) {
9
+ return;
10
+ }
11
+
12
+ if (node.id.name !== 'nextConfig') {
13
+ return;
14
+ }
15
+
16
+ if (node.init?.type !== AST_NODE_TYPES.ObjectExpression) {
17
+ return;
18
+ }
19
+
20
+ const skipTrailingSlashRedirectNode = node.init.properties.find(
21
+ (property) =>
22
+ 'key' in property &&
23
+ property.key.type === AST_NODE_TYPES.Identifier &&
24
+ property.key.name === 'skipTrailingSlashRedirect'
25
+ );
26
+
27
+ if (
28
+ !skipTrailingSlashRedirectNode ||
29
+ skipTrailingSlashRedirectNode.type !== AST_NODE_TYPES.Property
30
+ ) {
31
+ return;
32
+ }
33
+
34
+ if (
35
+ skipTrailingSlashRedirectNode.value.type === AST_NODE_TYPES.Literal &&
36
+ skipTrailingSlashRedirectNode.value.value === true
37
+ ) {
38
+ return;
39
+ }
40
+
41
+ context.report({
42
+ node: skipTrailingSlashRedirectNode,
43
+ messageId: 'skipTrailingSlashRedirect',
44
+ fix: (fixer) =>
45
+ fixer.replaceText(skipTrailingSlashRedirectNode.value, 'true')
46
+ });
47
+ }
48
+ };
49
+ },
50
+ meta: {
51
+ messages: {
52
+ skipTrailingSlashRedirect:
53
+ 'The `skipTrailingSlashRedirect` value must be true.'
54
+ },
55
+ type: 'problem',
56
+ fixable: 'code',
57
+ schema: []
58
+ },
59
+ defaultOptions: []
60
+ });