eslint-plugin-smarthr 0.3.7 → 0.3.8

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
@@ -2,6 +2,14 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.3.8](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.3.7...v0.3.8) (2023-09-01)
6
+
7
+
8
+ ### Features
9
+
10
+ * a11y-anchor-has-href-attribute の next, react-router-dom用オプションをpackage.jsonを解析して自動設定するように修正 ([#71](https://github.com/kufu/eslint-plugin-smarthr/issues/71)) ([8321433](https://github.com/kufu/eslint-plugin-smarthr/commit/832143385dd92bfd6fe45acd959038deea5cd1fe))
11
+ * a11y-anchor-has-href-attributeをhref="" や href="#" の場合、エラーとなるように修正 ([#75](https://github.com/kufu/eslint-plugin-smarthr/issues/75)) ([738ab65](https://github.com/kufu/eslint-plugin-smarthr/commit/738ab6598111dcf573a35d24f9d1baeda0506b4f))
12
+
5
13
  ### [0.3.7](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.3.6...v0.3.7) (2023-08-24)
6
14
 
7
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-smarthr",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "author": "SmartHR",
5
5
  "license": "MIT",
6
6
  "description": "A sharable ESLint plugin for SmartHR",
@@ -12,13 +12,7 @@
12
12
  ```js
13
13
  {
14
14
  rules: {
15
- 'smarthr/a11y-anchor-has-href-attribute': [
16
- 'error', // 'warn', 'off'
17
- // {
18
- // nextjs: true,
19
- // react_router: true,
20
- // },
21
- ]
15
+ 'smarthr/a11y-anchor-has-href-attribute': 'error', // 'warn', 'off'
22
16
  },
23
17
  }
24
18
  ```
@@ -39,9 +33,9 @@
39
33
  <XxxAnchor href={hoge}>any</XxxAnchor>
40
34
  <XxxLink href={undefined}>any</XxxLink>
41
35
 
42
- // nextjs: true
36
+ // nextを利用している場合
43
37
  <Link href={hoge}><a>any</a></Link>
44
38
 
45
- // react_router: true
39
+ // react-router-domを利用している場合
46
40
  <Link to={hoge}>any</Link>
47
41
  ```
@@ -1,5 +1,27 @@
1
+ const JSON5 = require('json5')
2
+ const fs = require('fs')
3
+
1
4
  const { generateTagFormatter } = require('../../libs/format_styled_components')
2
5
 
6
+ const OPTION = (() => {
7
+ const file = `${process.cwd()}/package.json`
8
+
9
+ if (!fs.existsSync(file)) {
10
+ return {}
11
+ }
12
+
13
+ const json = JSON5.parse(fs.readFileSync(file))
14
+ const dependencies = [
15
+ ...Object.keys(json.dependencies || {}),
16
+ ...Object.keys(json.devDependencies || {}),
17
+ ]
18
+
19
+ return {
20
+ nextjs: dependencies.includes('next'),
21
+ react_router: dependencies.includes('react-router-dom'),
22
+ }
23
+ })()
24
+
3
25
  const EXPECTED_NAMES = {
4
26
  'Anchor$': 'Anchor$',
5
27
  'Link$': 'Link$',
@@ -7,59 +29,47 @@ const EXPECTED_NAMES = {
7
29
  }
8
30
 
9
31
  const REGEX_TARGET = /(Anchor|Link|^a)$/
10
- const check = (node, option) => {
11
- let result = baseCheck(node)
12
-
13
- if (
14
- result && (
15
- (option.nextjs && !nextCheck(node)) ||
16
- (option.react_router && !reactRouterCheck(node))
17
- )
18
- ) {
19
- result = null
20
- }
32
+ const check = (node) => {
33
+ const result = baseCheck(node)
21
34
 
22
- return result
35
+ return result && ((OPTION.nextjs && !nextCheck(node)) || (OPTION.react_router && !reactRouterCheck(node))) ? null : result
23
36
  }
24
37
  const baseCheck = (node) => {
25
38
  const nodeName = node.name.name || ''
26
39
 
27
- if (nodeName.match(REGEX_TARGET)) {
28
- const href = node.attributes.find((a) => a.name?.name == 'href')
29
-
30
- if (!href || !href.value) {
31
- return nodeName
32
- }
33
- }
34
-
35
- return false
40
+ return nodeName.match(REGEX_TARGET) && checkExistAttribute(node, findHrefAttribute) ? nodeName : false
36
41
  }
37
42
  const nextCheck = (node) => {
38
43
  // HINT: next/link で `Link>a` という構造がありえるので直上のJSXElementを調べる
39
44
  const target = node.parent.parent.openingElement
40
45
 
41
- if (target) {
42
- return baseCheck(target)
43
- }
44
-
45
- return false
46
+ return target ? baseCheck(target) : false
46
47
  }
47
- const reactRouterCheck = (node) => {
48
- const href = node.attributes.find((a) => a.name?.name == 'to')
48
+ const reactRouterCheck = (node) => checkExistAttribute(node, findToAttribute)
49
+
50
+ const checkExistAttribute = (node, find) => {
51
+ const attr = node.attributes.find(find)?.value
49
52
 
50
- return !href || !href.value
53
+ return (
54
+ !attr ||
55
+ isNullTextHref(attr) ||
56
+ (attr.type === 'JSXExpressionContainer' && isNullTextHref(attr.expression))
57
+ )
51
58
  }
59
+ const isNullTextHref = (attr) => attr.type === 'Literal' && (attr.value === '' || attr.value === '#')
52
60
 
53
- const SCHEMA = [
54
- {
55
- type: 'object',
56
- properties: {
57
- nextjs: { type: 'boolean' },
58
- react_router: { type: 'boolean' },
59
- },
60
- additionalProperties: false,
61
- }
62
- ]
61
+ const findHrefAttribute = (a) => a.name?.name == 'href'
62
+ const findToAttribute = (a) => a.name?.name == 'to'
63
+
64
+ const MESSAGE_SUFFIX = ` に href 属性を正しく設定してください
65
+ - onClickなどでページ遷移する場合でもhref属性に遷移先のURIを設定してください
66
+ - Cmd + clickなどのキーボードショートカットに対応出来ます
67
+ - onClickなどの動作がURLの変更を行わない場合、button要素でマークアップすることを検討してください
68
+ - href属性に空文字(""など)や '#' が設定されている場合、実質画面遷移を行わないため、同様にbutton要素でマークアップすることを検討してください
69
+ - リンクが存在せず無効化されていることを表したい場合、href属性に undefined を設定してください
70
+ - button要素のdisabled属性が設定された場合に相当します`
71
+
72
+ const SCHEMA = []
63
73
 
64
74
  module.exports = {
65
75
  meta: {
@@ -67,20 +77,15 @@ module.exports = {
67
77
  schema: SCHEMA,
68
78
  },
69
79
  create(context) {
70
- const option = context.options[0] || {}
71
-
72
80
  return {
73
81
  ...generateTagFormatter({ context, EXPECTED_NAMES }),
74
82
  JSXOpeningElement: (node) => {
75
- const nodeName = check(node, option)
83
+ const nodeName = check(node)
76
84
 
77
85
  if (nodeName) {
78
86
  context.report({
79
87
  node,
80
- message: `${nodeName} に href 属性を設定してください。
81
- - onClickなどでページ遷移する場合、href属性に遷移先のURIを設定してください。Cmd + clickなどのキーボードショートカットに対応出来ます。
82
- - onClickなどの動作がURLの変更を行わない場合、リンクではなくbuttonでマークアップすることを検討してください。
83
- - リンクを無効化することを表したい場合、href属性に undefined を設定してください。`,
88
+ message: `${nodeName}${MESSAGE_SUFFIX}`,
84
89
  })
85
90
  }
86
91
  },
@@ -13,15 +13,26 @@ const EXPECTED_NAMES = {
13
13
  }
14
14
  const TARGET_TAG_NAME_REGEX = new RegExp(`(${Object.keys(EXPECTED_NAMES).join('|')})`)
15
15
  const INPUT_NAME_REGEX = /^[a-zA-Z0-9_\[\]]+$/
16
+ const INPUT_TAG_REGEX = /(i|I)nput$/
17
+
18
+ const findNameAttr = (a) => a?.name?.name === 'name'
19
+ const findRadioInput = (a) => a.name?.name === 'type' && a.value.value === 'radio'
20
+
21
+ const MESSAGE_PART_FORMAT = `"${INPUT_NAME_REGEX.toString()}"にmatchするフォーマットで命名してください`
22
+ const MESSAGE_UNDEFINED_NAME_PART = `
23
+ - ブラウザの自動補完が有効化されるなどのメリットがあります
24
+ - より多くのブラウザが自動補完を行える可能性を上げるため、${MESSAGE_PART_FORMAT}`
25
+ const MESSAGE_UNDEFINED_FOR_RADIO = `にグループとなる他のinput[radio]と同じname属性を指定してください
26
+ - 適切に指定することで同じname属性を指定したinput[radio]とグループが確立され、適切なキーボード操作を行えるようになります${MESSAGE_UNDEFINED_NAME_PART}`
27
+ const MESSAGE_UNDEFINED_FOR_NOT_RADIO = `にname属性を指定してください${MESSAGE_UNDEFINED_NAME_PART}`
28
+ const MESSAGE_NAME_FORMAT_SUFFIX = `はブラウザの自動補完が適切に行えない可能性があるため${MESSAGE_PART_FORMAT}`
29
+
30
+ const SCHEMA = []
16
31
 
17
32
  module.exports = {
18
33
  meta: {
19
34
  type: 'problem',
20
- messages: {
21
- 'format-styled-components': '{{ message }}',
22
- 'a11y-input-has-name-attribute': '{{ message }}',
23
- },
24
- schema: [],
35
+ schema: SCHEMA,
25
36
  },
26
37
  create(context) {
27
38
  return {
@@ -29,41 +40,31 @@ module.exports = {
29
40
  JSXOpeningElement: (node) => {
30
41
  const nodeName = node.name.name || '';
31
42
 
32
- if (!nodeName.match(TARGET_TAG_NAME_REGEX)) {
33
- return
34
- }
43
+ if (nodeName.match(TARGET_TAG_NAME_REGEX)) {
44
+ const nameAttr = node.attributes.find(findNameAttr)
35
45
 
36
- const nameAttr = node.attributes.find((a) => a?.name?.name === 'name')
46
+ if (!nameAttr) {
47
+ const isRadio =
48
+ nodeName.match(/RadioButton$/) ||
49
+ (nodeName.match(INPUT_TAG_REGEX) && node.attributes.some(findRadioInput));
37
50
 
38
- if (!nameAttr) {
39
- const isRadio =
40
- nodeName.match(/RadioButton$/) ||
41
- (nodeName.match(/(i|I)nput$/) && node.attributes.some(
42
- (a) => a.name?.name === 'type' && a.value.value === 'radio'
43
- ));
44
-
45
- context.report({
46
- node,
47
- messageId: 'a11y-input-has-name-attribute',
48
- data: {
49
- message: `${nodeName} にname属性を指定してください。適切に指定することで${isRadio ? 'グループが確立され、キーボード操作しやすくなる' : 'ブラウザの自動補完が有効化される'}などのメリットがあります。`,
50
- },
51
- });
52
- } else {
53
- const nameValue = nameAttr.value?.value || ''
54
-
55
- if (nameValue && !nameValue.match(INPUT_NAME_REGEX)) {
56
51
  context.report({
57
52
  node,
58
- messageId: 'a11y-input-has-name-attribute',
59
- data: {
60
- message: `${nodeName} のname属性の値(${nameValue})はブラウザの自動補完が適切に行えない可能性があるため ${INPUT_NAME_REGEX.toString()} にmatchするフォーマットで命名してください。`,
61
- },
53
+ message: `${nodeName} ${isRadio ? MESSAGE_UNDEFINED_FOR_RADIO : MESSAGE_UNDEFINED_FOR_NOT_RADIO}`,
62
54
  });
55
+ } else {
56
+ const nameValue = nameAttr.value?.value || ''
57
+
58
+ if (nameValue && !nameValue.match(INPUT_NAME_REGEX)) {
59
+ context.report({
60
+ node,
61
+ message: `${nodeName} のname属性の値(${nameValue})${MESSAGE_NAME_FORMAT_SUFFIX}`,
62
+ });
63
+ }
63
64
  }
64
65
  }
65
66
  },
66
67
  };
67
68
  },
68
69
  };
69
- module.exports.schema = [];
70
+ module.exports.schema = SCHEMA;
@@ -1,3 +1,10 @@
1
+ const MESSAGE_NEW_DATE = `'new Date(arg)' のように引数を一つだけ指定したDate instanceの生成は実行環境によって結果が異なるため、以下のいずれかの方法に変更してください
2
+ - 'new Date(2022, 12 - 1, 31)' のように数値を個別に指定する
3
+ - dayjsなど、日付系ライブラリを利用する (例: 'dayjs(arg).toDate()')`
4
+ const MESSAGE_PARSE = `Date.parse は実行環境によって結果が異なるため、以下のいずれかの方法に変更してください
5
+ - 'new Date(2022, 12 - 1, 31).getTime()' のように数値を個別に指定する
6
+ - dayjsなど、日付系ライブラリを利用する (例: 'dayjs(arg).valueOf()')`
7
+
1
8
  module.exports = {
2
9
  meta: {
3
10
  type: 'problem',
@@ -12,7 +19,7 @@ module.exports = {
12
19
  ) {
13
20
  context.report({
14
21
  node,
15
- message: "'new Date(arg)' のように引数一つのみの指定方は実行環境により結果が変わる可能性があるため 'new Date(2022, 12 - 1, 31)' のようにparseするなど他の方法を検討してください。",
22
+ message: MESSAGE_NEW_DATE,
16
23
  });
17
24
  }
18
25
  },
@@ -23,7 +30,7 @@ module.exports = {
23
30
  ) {
24
31
  context.report({
25
32
  node,
26
- message: 'Date.parse は日付形式の解釈がブラウザによって異なるため、他の手段を検討してください',
33
+ message: MESSAGE_PARSE,
27
34
  });
28
35
  }
29
36
  },
@@ -12,10 +12,13 @@ const ruleTester = new RuleTester({
12
12
  },
13
13
  })
14
14
 
15
- const generateErrorText = (name) => `${name} に href 属性を設定してください。
16
- - onClickなどでページ遷移する場合、href属性に遷移先のURIを設定してください。Cmd + clickなどのキーボードショートカットに対応出来ます。
17
- - onClickなどの動作がURLの変更を行わない場合、リンクではなくbuttonでマークアップすることを検討してください。
18
- - リンクを無効化することを表したい場合、href属性に undefined を設定してください。`
15
+ const generateErrorText = (name) => `${name} に href 属性を正しく設定してください
16
+ - onClickなどでページ遷移する場合でもhref属性に遷移先のURIを設定してください
17
+ - Cmd + clickなどのキーボードショートカットに対応出来ます
18
+ - onClickなどの動作がURLの変更を行わない場合、button要素でマークアップすることを検討してください
19
+ - href属性に空文字(""など)や '#' が設定されている場合、実質画面遷移を行わないため、同様にbutton要素でマークアップすることを検討してください
20
+ - リンクが存在せず無効化されていることを表したい場合、href属性に undefined を設定してください
21
+ - button要素のdisabled属性が設定された場合に相当します`
19
22
 
20
23
  ruleTester.run('a11y-anchor-has-href-attribute', rule, {
21
24
  valid: [
@@ -42,12 +45,7 @@ ruleTester.run('a11y-anchor-has-href-attribute', rule, {
42
45
  code: `<Link href="hoge">ほげ</Link>`,
43
46
  },
44
47
  {
45
- code: `<Link href="hoge"><a>ほげ</a></Link>`,
46
- options: [{ nextjs: true }],
47
- },
48
- {
49
- code: `<Link to="hoge">ほげ</Link>`,
50
- options: [{ react_router: true }],
48
+ code: `<Link href="#fuga">ほげ</Link>`,
51
49
  },
52
50
  ],
53
51
  invalid: [
@@ -61,7 +59,11 @@ ruleTester.run('a11y-anchor-has-href-attribute', rule, {
61
59
  { code: `<HogeLink>hoge</HogeLink>`, errors: [{ message: generateErrorText('HogeLink') }] },
62
60
  { code: `<HogeLink href>hoge</HogeLink>`, errors: [{ message: generateErrorText('HogeLink') }] },
63
61
  { code: `<HogeLink href="hoge"><a>hoge</a></HogeLink>`, errors: [{ message: generateErrorText('a') }] },
64
- { code: `<HogeLink><a>hoge</a></HogeLink>`, options: [{ nextjs: true }], errors: [{ message: generateErrorText('a') }] },
65
62
  { code: `<HogeLink to="hoge">hoge</HogeLink>`, errors: [{ message: generateErrorText('HogeLink') }] },
63
+ { code: `<HogeLink href="">hoge</HogeLink>`, errors: [{ message: generateErrorText('HogeLink') }] },
64
+ { code: `<HogeLink href={""}>hoge</HogeLink>`, errors: [{ message: generateErrorText('HogeLink') }] },
65
+ { code: `<HogeLink href={''}>hoge</HogeLink>`, errors: [{ message: generateErrorText('HogeLink') }] },
66
+ { code: `<HogeLink href="#">hoge</HogeLink>`, errors: [{ message: generateErrorText('HogeLink') }] },
67
+ { code: `<HogeLink href={'#'}>hoge</HogeLink>`, errors: [{ message: generateErrorText('HogeLink') }] },
66
68
  ]
67
69
  })
@@ -12,6 +12,12 @@ const ruleTester = new RuleTester({
12
12
  },
13
13
  });
14
14
 
15
+ const MESSAGE_SUFFIX = `
16
+ - ブラウザの自動補完が有効化されるなどのメリットがあります
17
+ - より多くのブラウザが自動補完を行える可能性を上げるため、\"/^[a-zA-Z0-9_\\[\\]]+$/\"にmatchするフォーマットで命名してください`
18
+ const MESSAGE_RADIO_SUFFIX = `
19
+ - 適切に指定することで同じname属性を指定したinput[radio]とグループが確立され、適切なキーボード操作を行えるようになります${MESSAGE_SUFFIX}`
20
+
15
21
  ruleTester.run('a11y-input-has-name-attribute', rule, {
16
22
  valid: [
17
23
  { code: `import styled from 'styled-components'` },
@@ -37,18 +43,18 @@ ruleTester.run('a11y-input-has-name-attribute', rule, {
37
43
  { code: 'const Hoge = styled.input``', errors: [ { message: `Hogeを正規表現 "/Input$/" がmatchする名称に変更してください` } ] },
38
44
  { code: 'const Hoge = styled.Input``', errors: [ { message: `Hogeを正規表現 "/Input$/" がmatchする名称に変更してください` } ] },
39
45
  { code: 'const Hoge = styled(RadioButton)``', errors: [ { message: `Hogeを正規表現 "/RadioButton$/" がmatchする名称に変更してください` } ] },
40
- { code: '<input />', errors: [ { message: 'input にname属性を指定してください。適切に指定することでブラウザの自動補完が有効化されるなどのメリットがあります。' } ] },
41
- { code: '<input type="date" />', errors: [ { message: 'input にname属性を指定してください。適切に指定することでブラウザの自動補完が有効化されるなどのメリットがあります。' } ] },
42
- { code: '<Input type="checkbox" />', errors: [ { message: 'Input にname属性を指定してください。適切に指定することでブラウザの自動補完が有効化されるなどのメリットがあります。' } ] },
43
- { code: '<input type="radio" />', errors: [ { message: 'input name属性を指定してください。適切に指定することでグループが確立され、キーボード操作しやすくなるなどのメリットがあります。' } ] },
44
- { code: '<HogeInput type="radio" />', errors: [ { message: 'HogeInput name属性を指定してください。適切に指定することでグループが確立され、キーボード操作しやすくなるなどのメリットがあります。' } ] },
45
- { code: '<HogeInput type="text" />', errors: [ { message: 'HogeInput にname属性を指定してください。適切に指定することでブラウザの自動補完が有効化されるなどのメリットがあります。' } ] },
46
- { code: '<HogeRadioButton />', errors: [ { message: 'HogeRadioButton name属性を指定してください。適切に指定することでグループが確立され、キーボード操作しやすくなるなどのメリットがあります。' } ] },
47
- { code: '<select />', errors: [ { message: 'select にname属性を指定してください。適切に指定することでブラウザの自動補完が有効化されるなどのメリットがあります。' } ] },
48
- { code: '<HogeSelect />', errors: [ { message: 'HogeSelect にname属性を指定してください。適切に指定することでブラウザの自動補完が有効化されるなどのメリットがあります。' } ] },
49
- { code: '<textarea />', errors: [ { message: 'textarea にname属性を指定してください。適切に指定することでブラウザの自動補完が有効化されるなどのメリットがあります。' } ] },
50
- { code: '<HogeTextarea />', errors: [ { message: 'HogeTextarea にname属性を指定してください。適切に指定することでブラウザの自動補完が有効化されるなどのメリットがあります。' } ] },
51
- { code: '<input type="radio" name="ほげ" />', errors: [ { message: 'input のname属性の値(ほげ)はブラウザの自動補完が適切に行えない可能性があるため /^[a-zA-Z0-9_\\[\\]]+$/ にmatchするフォーマットで命名してください。' } ] },
52
- { code: '<select name="hoge[fuga][0][あいうえお]" />', errors: [ { message: 'select のname属性の値(hoge[fuga][0][あいうえお])はブラウザの自動補完が適切に行えない可能性があるため /^[a-zA-Z0-9_\\[\\]]+$/ にmatchするフォーマットで命名してください。' } ] },
46
+ { code: '<input />', errors: [ { message: `input にname属性を指定してください${MESSAGE_SUFFIX}` } ] },
47
+ { code: '<input type="date" />', errors: [ { message: `input にname属性を指定してください${MESSAGE_SUFFIX}` } ] },
48
+ { code: '<Input type="checkbox" />', errors: [ { message: `Input にname属性を指定してください${MESSAGE_SUFFIX}` } ] },
49
+ { code: '<input type="radio" />', errors: [ { message: `input にグループとなる他のinput[radio]と同じname属性を指定してください${MESSAGE_RADIO_SUFFIX}` } ] },
50
+ { code: '<HogeInput type="radio" />', errors: [ { message: `HogeInput にグループとなる他のinput[radio]と同じname属性を指定してください${MESSAGE_RADIO_SUFFIX}` } ] },
51
+ { code: '<HogeInput type="text" />', errors: [ { message: `HogeInput にname属性を指定してください${MESSAGE_SUFFIX}` } ] },
52
+ { code: '<HogeRadioButton />', errors: [ { message: `HogeRadioButton にグループとなる他のinput[radio]と同じname属性を指定してください${MESSAGE_RADIO_SUFFIX}` } ] },
53
+ { code: '<select />', errors: [ { message: `select にname属性を指定してください${MESSAGE_SUFFIX}` } ] },
54
+ { code: '<HogeSelect />', errors: [ { message: `HogeSelect にname属性を指定してください${MESSAGE_SUFFIX}` } ] },
55
+ { code: '<textarea />', errors: [ { message: `textarea にname属性を指定してください${MESSAGE_SUFFIX}` } ] },
56
+ { code: '<HogeTextarea />', errors: [ { message: `HogeTextarea にname属性を指定してください${MESSAGE_SUFFIX}` } ] },
57
+ { code: '<input type="radio" name="ほげ" />', errors: [ { message: 'input のname属性の値(ほげ)はブラウザの自動補完が適切に行えない可能性があるため"/^[a-zA-Z0-9_\\[\\]]+$/"にmatchするフォーマットで命名してください' } ] },
58
+ { code: '<select name="hoge[fuga][0][あいうえお]" />', errors: [ { message: 'select のname属性の値(hoge[fuga][0][あいうえお])はブラウザの自動補完が適切に行えない可能性があるため"/^[a-zA-Z0-9_\\[\\]]+$/"にmatchするフォーマットで命名してください' } ] },
53
59
  ],
54
60
  });
@@ -12,8 +12,12 @@ const ruleTester = new RuleTester({
12
12
  },
13
13
  })
14
14
 
15
- const errorNewDate = "'new Date(arg)' のように引数一つのみの指定方は実行環境により結果が変わる可能性があるため 'new Date(2022, 12 - 1, 31)' のようにparseするなど他の方法を検討してください。"
16
- const errorDateParse = 'Date.parse は日付形式の解釈がブラウザによって異なるため、他の手段を検討してください'
15
+ const errorNewDate = `'new Date(arg)' のように引数を一つだけ指定したDate instanceの生成は実行環境によって結果が異なるため、以下のいずれかの方法に変更してください
16
+ - 'new Date(2022, 12 - 1, 31)' のように数値を個別に指定する
17
+ - dayjsなど、日付系ライブラリを利用する (例: 'dayjs(arg).toDate()')`
18
+ const errorDateParse = `Date.parse は実行環境によって結果が異なるため、以下のいずれかの方法に変更してください
19
+ - 'new Date(2022, 12 - 1, 31).getTime()' のように数値を個別に指定する
20
+ - dayjsなど、日付系ライブラリを利用する (例: 'dayjs(arg).valueOf()')`
17
21
 
18
22
  ruleTester.run('best-practice-for-date', rule, {
19
23
  valid: [