Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
[1.0.1] Add one more test case for remove-event-listener rule
Browse files Browse the repository at this point in the history
  • Loading branch information
isnifer committed Aug 23, 2018
1 parent a9a4e76 commit 0a261bd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

## [1.0.1] - 2018-08-23
### Updated
- Added test case for tipsi/remove-event-listener when callee is Identifier

## [1.0.0] - 2018-08-23
### Added
- rule tipsi/remove-event-listener
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# eslint-plugin-tipsi

### List or rules
## List or rules
* [tipsi/remove-event-listener](/docs/rules/remove-event-listener.md)

## Changelog
[[1.0.1] - 2018-08-23](/CHANGELOG.md#101---2018-08-23)

[[1.0.0] - 2018-08-23](/CHANGELOG.md#100---2018-08-23)
7 changes: 6 additions & 1 deletion lib/rules/remove-event-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = {
create: (context) => {
const listeners = {}

const isNodeIdentifier = node => get(node, 'type') === 'Identifier'
const isNodeMemberExpression = node => get(node, 'type') === 'MemberExpression'
const isNodeThisExpression = node => get(node, 'type') === 'ThisExpression'
const isNodeFunctionExpression = node => get(node, 'type') === 'FunctionExpression'
Expand All @@ -40,6 +41,10 @@ module.exports = {
const parseMemberExpression = (node) => {
let value

if (isNodeIdentifier(node.object)) {
value = node.object.name
}

if (isNodeMemberExpression(node.object)) {
value = parseMemberExpression(node.object)
}
Expand All @@ -51,7 +56,7 @@ module.exports = {
return value
}

const isNodeIdentifier = node => get(node, 'type') === 'Identifier'

const isCalleePropertyAddEventListener = property => (
get(property, 'name') === ADD_EVENT_LISTENER && ADD_EVENT_LISTENER
)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-tipsi",
"version": "1.0.0",
"version": "1.0.1",
"description": "Custom Tipsi rules for eslint",
"main": "index.js",
"scripts": {
Expand Down
10 changes: 4 additions & 6 deletions tests/lib/rules/remove-event-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,21 @@ ruleTester.run('remove-event-listener', removeEventListener, {
}
componentDidMount() {
this.rootNodeRef.addEventListener('click', this.handleRootNodeClick)
window.addEventListener('click', this.handleRootNodeClick)
}
componentWillUnmount() {
this.rootNodeRef.removeEventListener('click', this.handleRootNodeKeyPress)
window.removeEventListener('click', this.handleRootNodeKeyPress)
}
render() {
return (
<div ref={node => this.rootNodeRef = node} />
)
return null
}
}
`,
errors: [{
message: 'this.handleRootNodeClick and this.handleRootNodeKeyPress ' +
'on this.rootNodeRef for click do not match',
'on window for click do not match',
}],
},
{
Expand Down

0 comments on commit 0a261bd

Please sign in to comment.