Skip to content

Commit

Permalink
v1.2.0 (#63)
Browse files Browse the repository at this point in the history
v1.2.0
  • Loading branch information
aooen authored May 17, 2022
2 parents 86f5655 + 2261736 commit fa54840
Show file tree
Hide file tree
Showing 10 changed files with 1,504 additions and 2,967 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
> Documents are written by Korean only.
- [hooks-deps-element-newline](./docs/hooks-deps-element-newline.md)
- [no-classnames-with-one-argument](./docs/no-classnames-with-one-argument.md)
- [no-translate-with-template-literal](./docs/no-translate-with-template-literal.md)
- [pascal-case-enum-name](./docs/pascal-case-enum-name.md)
- [pascal-case-interface-name](./docs/pascal-case-interface-name.md)
- [pascal-case-type-name](./docs/pascal-case-type-name.md)
- [prevent-destructured-argument-callback-in-intersection-observer](./docs/prevent-destructured-argument-callback-in-intersection-observer.md)

## See also
- https://github.com/channel-io/eslint-config
46 changes: 46 additions & 0 deletions __tests__/no-translate-with-template-literal.js
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.' }],
},
],
})
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.' }],
}
]
})
12 changes: 12 additions & 0 deletions docs/no-translate-with-template-literal.md
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 인지 확인합니다.
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로 사용할 경우 배열 구조 분해를 통해 인자를 받고 있더라도 감지할 수 없습니다.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const hooksDepsElementNewline = require('./rules/hooks-deps-element-newline')
const noClassnamesWithOneArgument = require('./rules/no-classnames-with-one-argument')
const noTranslateWithTemplateLiteral = require('./rules/no-translate-with-template-literal')
const pascalCaseEnumName = require('./rules/pascal-case-enum-name')
const pascalCaseInterfaceName = require('./rules/pascal-case-interface-name')
const pascalCaseTypeName = require('./rules/pascal-case-type-name')
Expand All @@ -8,6 +9,7 @@ module.exports = {
rules: {
'hooks-deps-element-newline': hooksDepsElementNewline,
'no-classnames-with-one-argument': noClassnamesWithOneArgument,
'no-translate-with-template-literal': noTranslateWithTemplateLiteral,
'pascal-case-enum-name': pascalCaseEnumName,
'pascal-case-interface-name': pascalCaseInterfaceName,
'pascal-case-type-name': pascalCaseTypeName,
Expand Down
Loading

0 comments on commit fa54840

Please sign in to comment.