Skip to content

Commit

Permalink
added syntax battery to test utils for future use + fixed #281
Browse files Browse the repository at this point in the history
  • Loading branch information
benmosher committed Apr 28, 2016
1 parent ddea58c commit f10db9f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).

## Unreleased
### Fixed
- [`no-named-as-default-member`] don't crash on rest props. ([#281], thanks [@SimenB])

## resolvers/webpack: Unreleased
### Changed
- automatically find webpack config with `interpret`-able extensions ([#287], thanks @taion)
Expand Down Expand Up @@ -191,6 +195,7 @@ for info on changes for earlier releases.
[#164]: https://github.com/benmosher/eslint-plugin-import/pull/164

[#286]: https://github.com/benmosher/eslint-plugin-import/issues/286
[#281]: https://github.com/benmosher/eslint-plugin-import/issues/281
[#216]: https://github.com/benmosher/eslint-plugin-import/issues/216
[#214]: https://github.com/benmosher/eslint-plugin-import/issues/214
[#210]: https://github.com/benmosher/eslint-plugin-import/issues/210
Expand Down Expand Up @@ -231,3 +236,4 @@ for info on changes for earlier releases.
[@jimbolla]: https://github.com/jimbolla
[@jquense]: https://github.com/jquense
[@jonboiser]: https://github.com/jonboiser
[@SimenB]: https://github.com/SimenB
9 changes: 5 additions & 4 deletions src/rules/no-named-as-default-member.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ module.exports = function(context) {
}

function handleDestructuringAssignment(node) {
if (!node.init) return

const isDestructure = (
node.id.type === 'ObjectPattern' && node.init.type === 'Identifier'
node.id.type === 'ObjectPattern' &&
node.init != null &&
node.init.type === 'Identifier'
)
if (!isDestructure) return

const objectName = node.init.name
for (const {key} of node.id.properties) {
for (const { key } of node.id.properties) {
if (key == null) continue // true for rest properties
storePropertyLookup(objectName, key.name, key)
}
}
Expand Down
5 changes: 2 additions & 3 deletions tests/src/rules/no-named-as-default-member.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {test} from '../utils'
import { test, SYNTAX_CASES } from '../utils'
import {RuleTester} from 'eslint'
import rule from 'rules/no-named-as-default-member'

Expand All @@ -11,8 +11,7 @@ ruleTester.run('no-named-as-default-member', rule, {
test({code: 'import {foo} from "./bar"; const baz = foo.baz;'}),
test({code: 'import * as named from "./named-exports"; const a = named.a'}),

// issue #249
test({code: 'for (const {foo, bar} of baz) {}'}),
...SYNTAX_CASES,
],

invalid: [
Expand Down
30 changes: 30 additions & 0 deletions tests/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,33 @@ export function testContext(settings) {
export function getFilename(file) {
return path.join(__dirname, '..', 'files', file || 'foo.js')
}

/**
* to be added as valid cases just to ensure no nullable fields are going
* to crash at runtinme
* @type {Array}
*/
export const SYNTAX_CASES = [

test({ code: 'for (let { foo, bar } of baz) {}' }),
test({ code: 'for (let [ foo, bar ] of baz) {}' }),

test({ code: 'const { x, y } = bar' }),
test({ code: 'const { x, y, ...z } = bar', parser: 'babel-eslint' }),

// all the exports
test({ code: 'export { x }' }),
test({ code: 'export { x as y }' }),

// not sure about these since they reference a file
// test({ code: 'export { x } from "./y.js"'}),
// test({ code: 'export * as y from "./y.js"', parser: 'babel-eslint'}),

test({ code: 'export const x = null' }),
test({ code: 'export var x = null' }),
test({ code: 'export let x = null' }),

test({ code: 'export default x' }),
test({ code: 'export default class x {}' }),

]

0 comments on commit f10db9f

Please sign in to comment.