-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.2.0
- Loading branch information
Showing
10 changed files
with
1,504 additions
and
2,967 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const ruleTester = require('./ruleTester') | ||
const rule = require('../rules/no-translate-with-template-literal') | ||
|
||
ruleTester.run('no-translate-with-template-literal', rule, { | ||
valid: [ | ||
{ | ||
code: `translate('my.foo.key')`, | ||
}, | ||
{ | ||
code: ` | ||
const TRANSLATE_KEY = 'my.foo.key' | ||
const translated = translate(TRANSLATE_KEY) | ||
`, | ||
}, | ||
{ | ||
code: ` | ||
const TRANSLATE_KEY = 'my.foo.key' | ||
const translated1 = i18n(TRANSLATE_KEY) | ||
const translated2 = t(TRANSLATE_KEY) | ||
`, | ||
options: [{ translateFuncNames: ['t', 'i18n'] }] | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
code: 'translate(`my.foo.${first}`)', | ||
errors: [{ message: 'Do not call translation method with template literal.' }], | ||
}, | ||
{ | ||
code: 'translate(`my.foo.${second}.${third}`)', | ||
errors: [{ message: 'Do not call translation method with template literal.' }], | ||
}, | ||
{ | ||
code: 'translate(`my.foo.${second}.${third}.fourth`)', | ||
errors: [{ message: 'Do not call translation method with template literal.' }], | ||
}, | ||
{ | ||
code: ` | ||
someItems.map((item) => ${'translate(`my.foo.${item.type}`)'}) | ||
`, | ||
errors: [{ message: 'Do not call translation method with template literal.' }], | ||
}, | ||
], | ||
}) |
69 changes: 69 additions & 0 deletions
69
__tests__/prevent-destructured-argument-callback-in-intersection-observer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const ruleTester = require('./ruleTester') | ||
const rule = require('../rules/prevent-destructured-argument-callback-in-intersection-observer') | ||
|
||
ruleTester.run('prevent-destructured-argument-callback-in-intersection-observer', rule, { | ||
valid: [ | ||
{ | ||
code: ` | ||
const observer = new IntersectionObserver((entries) => { | ||
something() | ||
}) | ||
`, | ||
}, | ||
{ | ||
code: ` | ||
const observer = new IntersectionObserver(function (entries) { | ||
something() | ||
}) | ||
`, | ||
}, | ||
{ | ||
code: ` | ||
const observer = new IntersectionObserver((e) => { | ||
something() | ||
}, { root: foo }) | ||
`, | ||
}, | ||
{ | ||
code: ` | ||
new IntersectionObserver((e) => { | ||
something() | ||
}, { root: foo }).observe(bar) | ||
`, | ||
} | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
const observer = new IntersectionObserver(([entry]) => { | ||
something() | ||
}) | ||
`, | ||
errors: [{ message: 'IntersectionObserver\'s callback should not destructure argument. Callback\'s `entries` argument can have multi value even observe only one element.' }], | ||
}, | ||
{ | ||
code: ` | ||
const observer = new IntersectionObserver(function ([entry]) { | ||
something() | ||
}) | ||
`, | ||
errors: [{ message: 'IntersectionObserver\'s callback should not destructure argument. Callback\'s `entries` argument can have multi value even observe only one element.' }], | ||
}, | ||
{ | ||
code: ` | ||
const observer = new IntersectionObserver(([e]) => { | ||
something() | ||
}, { root: foo }) | ||
`, | ||
errors: [{ message: 'IntersectionObserver\'s callback should not destructure argument. Callback\'s `entries` argument can have multi value even observe only one element.' }], | ||
}, | ||
{ | ||
code: ` | ||
new IntersectionObserver(([e]) => { | ||
something() | ||
}, { root: foo }).observe(bar) | ||
`, | ||
errors: [{ message: 'IntersectionObserver\'s callback should not destructure argument. Callback\'s `entries` argument can have multi value even observe only one element.' }], | ||
} | ||
] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# no-translate-with-template-literal | ||
> Restrict template literal argument for translation method | ||
## Concept | ||
- 번역 함수의 인자에는 template literal 문법의 문자열을 사용할 수 없습니다. | ||
|
||
## Options | ||
- `translateFuncNames: string[]` (기본값 `['translate']`): 번역 함수의 이름을 지정합니다. | ||
|
||
## Logic | ||
1. CallExpression 에서 함수의 이름이 `translateFuncName`인지 여부를 확인합니다. | ||
2. 함수의 인자가 template literal 인지 확인합니다. |
12 changes: 12 additions & 0 deletions
12
docs/prevent-destructured-argument-callback-in-intersection-observer.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# prevent-destructured-argument-callback-in-intersection-observer | ||
> IntersectionObserver's callback should not destructure argument. Callback's `entries` argument can have multi value even observe only one element. | ||
## Concept | ||
- IntersectionObserver 생성자 인자로 들어가는 콜백은 배열 구조 분해를 통해 인자를 받을 수 없습니다. | ||
|
||
## Logic | ||
1. NewExpression을 통해 IntersectionObserver를 생성하고, 그 첫번째 argument인 함수의 첫 파라미터가 ArrayPattern인지 확인합니다. | ||
- 만약 그렇다면 ```IntersectionObserver's callback should not destructure argument. Callback's `entries` argument can have multi value even observe only one element.```를 표시합니다. | ||
|
||
## Known-issue | ||
- 다른 곳에서 선언된 함수를 handler로 사용할 경우 배열 구조 분해를 통해 인자를 받고 있더라도 감지할 수 없습니다. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.