Skip to content

Commit

Permalink
Disallow spacing in object curlies or brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
novemberborn committed Oct 31, 2017
1 parent 0214325 commit 962af60
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.js
Expand Up @@ -14,7 +14,9 @@ module.exports = {
},
plugins: ['ava', 'import', 'node-globals', 'react', 'unicorn'],
rules: {
'array-bracket-spacing': ['error', 'never'],
'arrow-parens': ['error', 'as-needed'],
'computed-property-spacing': ['error', 'never'],
'import/default': 'error',
'import/extensions': ['error', {
js: 'never',
Expand Down Expand Up @@ -47,6 +49,7 @@ module.exports = {
}],
'no-var': 'error',
'no-warning-comments': 'warn',
'object-curly-spacing': ['error', 'never'],
'object-shorthand': 'error',
'prefer-const': 'error',
'promise/no-return-in-finally': 'error',
Expand All @@ -73,6 +76,9 @@ module.exports = {
'react/no-will-update-set-state': 'error',
'react/require-render-return': 'error',
'react/void-dom-elements-no-children': 'error',
'standard/array-bracket-even-spacing': 'off',
'standard/computed-property-even-spacing': 'off',
'standard/object-curly-even-spacing': 'off',
'unicorn/catch-error-name': 'error',
'unicorn/explicit-length-check': 'error',
'unicorn/no-abusive-eslint-disable': 'error',
Expand Down
6 changes: 3 additions & 3 deletions test/api.js
@@ -1,4 +1,4 @@
import { resolve as resolvePath } from 'path'
import {resolve as resolvePath} from 'path'

import test from 'ava'

Expand Down Expand Up @@ -50,7 +50,7 @@ test.cb('works with invalid files', t => {
endColumn: 16,
nodeType: 'Literal',
source: ' return "BAR:" + bar.toUpperCase()',
fix: { range: [32, 38], text: '\'BAR:\'' }
fix: {range: [32, 38], text: '\'BAR:\''}
},
{
ruleId: 'semi',
Expand All @@ -60,7 +60,7 @@ test.cb('works with invalid files', t => {
column: 2,
nodeType: 'ExpressionStatement',
source: '};',
fix: { range: [59, 61], text: '}' }
fix: {range: [59, 61], text: '}'}
}
],
errorCount: 2,
Expand Down
4 changes: 2 additions & 2 deletions test/cli.js
@@ -1,5 +1,5 @@
import { fork } from 'child_process'
import { resolve as resolvePath } from 'path'
import {fork} from 'child_process'
import {resolve as resolvePath} from 'path'

import test from 'ava'
import getStream from 'get-stream'
Expand Down
8 changes: 4 additions & 4 deletions test/patches/file-result-output.js
@@ -1,4 +1,4 @@
import { join } from 'path'
import {join} from 'path'
import test from 'ava'
import engine from 'standard-engine'
import patchFileResultOutput from '../../lib/patch-file-result-output'
Expand All @@ -14,7 +14,7 @@ test.beforeEach(t => {
stderr: ''
}

patchFileResultOutput({ linter: Linter }, {
patchFileResultOutput({linter: Linter}, {
error (output) {
t.context.stderr += output
},
Expand All @@ -28,7 +28,7 @@ test.beforeEach(t => {

async function checkOutput (t, out, ...args) {
const other = out === 'stderr' ? 'stdout' : 'stderr'
const { results } = await new Promise(resolve => {
const {results} = await new Promise(resolve => {
t.context.linter.lintFiles(...args, (_, result) => resolve(result))
})

Expand Down Expand Up @@ -56,7 +56,7 @@ test('patched lintFiles() propagates errors', async t => {
}
}

patchFileResultOutput({ linter: Linter })
patchFileResultOutput({linter: Linter})
const linter = new Linter(Object.assign({}, options))
const err = await t.throws(new Promise((resolve, reject) => {
linter.lintFiles([fixture], null, reject)
Expand Down
16 changes: 8 additions & 8 deletions test/patches/import-rule.js
Expand Up @@ -7,7 +7,7 @@ import applySettings from '../../lib/settings'

const NOT_PATCHED = new Error('Throw when unpatched code is run')
for (const rule of [extensionsRule, noExtraneousDependenciesRule]) {
const { create } = rule
const {create} = rule
rule.create = function (context) {
const base = create.call(this, context)
return Object.assign(base, {
Expand All @@ -19,23 +19,23 @@ for (const rule of [extensionsRule, noExtraneousDependenciesRule]) {

function makeStaticRequire (value) {
return {
callee: { type: 'Identifier', name: 'require' },
arguments: [ { type: 'Literal', value } ]
callee: {type: 'Identifier', name: 'require'},
arguments: [{type: 'Literal', value}]
}
}

function checkPatched (t, rule) {
applySettings({}, { fakeDependencies: ['^fake', '^reallyFake'] }, '/')
applySettings({}, {fakeDependencies: ['^fake', '^reallyFake']}, '/')

const instance = rule.create({
getFilename () { return 'test.js' },
options: []
})
{
t.notThrows(() => instance.ImportDeclaration({ source: { value: 'fake' } }))
t.notThrows(() => instance.ImportDeclaration({ source: { value: 'reallyFake' } }))
t.notThrows(() => instance.ImportDeclaration({ source: { value: 'faker' } }))
const err = t.throws(() => instance.ImportDeclaration({ source: { value: 'real' } }))
t.notThrows(() => instance.ImportDeclaration({source: {value: 'fake'}}))
t.notThrows(() => instance.ImportDeclaration({source: {value: 'reallyFake'}}))
t.notThrows(() => instance.ImportDeclaration({source: {value: 'faker'}}))
const err = t.throws(() => instance.ImportDeclaration({source: {value: 'real'}}))
t.true(err === NOT_PATCHED)
}

Expand Down
16 changes: 8 additions & 8 deletions test/settings.js
@@ -1,12 +1,12 @@
import { join } from 'path'
import {join} from 'path'

import test from 'ava'

import applySettings from '../lib/settings'

test('uses existing rules object', t => {
const rules = {}
const eslintConfig = { rules }
const eslintConfig = {rules}

applySettings(eslintConfig, {}, '/')
t.true(eslintConfig.rules === rules)
Expand Down Expand Up @@ -34,7 +34,7 @@ test('overrides import/no-extraneous-dependencies with default devDependencies',

test('supports allowDevDependencies with string value', t => {
const eslintConfig = {}
applySettings(eslintConfig, { allowDevDependencies: 'foo.js' }, '/root')
applySettings(eslintConfig, {allowDevDependencies: 'foo.js'}, '/root')

t.deepEqual(eslintConfig.rules['import/no-extraneous-dependencies'], ['error', {
devDependencies: ['/root/foo.js']
Expand All @@ -43,7 +43,7 @@ test('supports allowDevDependencies with string value', t => {

test('supports allowDevDependencies with array value', t => {
const eslintConfig = {}
applySettings(eslintConfig, { allowDevDependencies: ['foo.js', 'bar.js'] }, '/root')
applySettings(eslintConfig, {allowDevDependencies: ['foo.js', 'bar.js']}, '/root')

t.deepEqual(eslintConfig.rules['import/no-extraneous-dependencies'], ['error', {
devDependencies: ['/root/foo.js', '/root/bar.js']
Expand All @@ -52,7 +52,7 @@ test('supports allowDevDependencies with array value', t => {

test('supports fakeDependencies with string value', t => {
const eslintConfig = {}
applySettings(eslintConfig, { fakeDependencies: 'foo.js' }, '/root')
applySettings(eslintConfig, {fakeDependencies: 'foo.js'}, '/root')

t.deepEqual(eslintConfig.rules['import/no-unresolved'], ['error', {
commonjs: true,
Expand All @@ -62,7 +62,7 @@ test('supports fakeDependencies with string value', t => {

test('supports fakeDependencies with array value', t => {
const eslintConfig = {}
applySettings(eslintConfig, { fakeDependencies: ['foo.js', 'bar.js'] }, '/root')
applySettings(eslintConfig, {fakeDependencies: ['foo.js', 'bar.js']}, '/root')

t.deepEqual(eslintConfig.rules['import/no-unresolved'], ['error', {
commonjs: true,
Expand All @@ -74,7 +74,7 @@ const RESOLVERS_DIR = join(__dirname, 'fixtures', 'resolvers')

test('supports resolvers — resolves string values from the rootDir', t => {
const eslintConfig = {}
const settings = { resolvers: 'foo' }
const settings = {resolvers: 'foo'}
applySettings(eslintConfig, settings, RESOLVERS_DIR)

t.deepEqual(eslintConfig.baseConfig, {
Expand Down Expand Up @@ -106,7 +106,7 @@ test('supports resolvers — resolves object keys from the rootDir', t => {

test('supports resolvers — throws if values cannot be resolved', t => {
const eslintConfig = {}
const settings = { resolvers: 'foo' }
const settings = {resolvers: 'foo'}

const err = t.throws(() => applySettings(eslintConfig, settings, '/root'))
t.true(err.message === 'Could not resolve \'foo\' import resolver')
Expand Down

0 comments on commit 962af60

Please sign in to comment.