Skip to content

Commit

Permalink
Rename isFormattingActivated to getIsFormattingActivated
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Bonnike committed Oct 15, 2019
1 parent 6b41541 commit cbcc91a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type FormattingConfiguration = {
[key in FormattingSettings]: boolean
}

const isFormattingActivated = () => {
const getIsFormattingActivated = () => {
const editorConfiguration = getConfiguration('editor')
const formattingToggleConfiguration = getConfiguration('formattingToggle')
const affectsConfiguration = formattingToggleConfiguration.get(
Expand All @@ -26,4 +26,4 @@ const isFormattingActivated = () => {
return isAnyRelevantSettingActivated
}

export default isFormattingActivated
export default getIsFormattingActivated
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FormattingSettings } from '../../constants'
import getConfiguration from '../getConfiguration'
import isFormattingActivated, { FormattingConfiguration } from './'
import getIsFormattingActivated, { FormattingConfiguration } from './'

jest.mock('../getConfiguration')

Expand All @@ -27,7 +27,7 @@ const mockGetConfiguration = (configurationMock: ConfigurationMock) =>
}
)

describe('The `isFormattingActivated` helper', () => {
describe('The `getIsFormattingActivated` helper', () => {
it('should return `true` if any of the formatting settings is enabled (without any custom `affects` configuration)', () => {
const testCases: ConfigurationMock[] = [
{
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('The `isFormattingActivated` helper', () => {
mockGetConfiguration(configurationMock)

const expected = true
const actual = isFormattingActivated()
const actual = getIsFormattingActivated()

expect(actual).toEqual(expected)
})
Expand Down Expand Up @@ -157,7 +157,7 @@ describe('The `isFormattingActivated` helper', () => {
mockGetConfiguration(configurationMock)

const expected = true
const actual = isFormattingActivated()
const actual = getIsFormattingActivated()

expect(actual).toEqual(expected)
})
Expand All @@ -173,7 +173,7 @@ describe('The `isFormattingActivated` helper', () => {
})

const expected = false
const actual = isFormattingActivated()
const actual = getIsFormattingActivated()

expect(actual).toEqual(expected)
})
Expand Down Expand Up @@ -244,7 +244,7 @@ describe('The `isFormattingActivated` helper', () => {
mockGetConfiguration(configurationMock)

const expected = false
const actual = isFormattingActivated()
const actual = getIsFormattingActivated()

expect(actual).toEqual(expected)
})
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/getStatusBarText/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import isFormattingActivated from '../isFormattingActivated'
import getIsFormattingActivated from '../getIsFormattingActivated'

export const ENABLED_TEXT = 'Formatting: $(check)'
export const DISABLED_TEXT = 'Formatting: $(x)'

const getStatusBarText = () => {
const shouldDisableFormatting = isFormattingActivated()
const isFormattingActivated = getIsFormattingActivated()

return shouldDisableFormatting ? ENABLED_TEXT : DISABLED_TEXT
return isFormattingActivated ? ENABLED_TEXT : DISABLED_TEXT
}

export default getStatusBarText
10 changes: 5 additions & 5 deletions src/helpers/getStatusBarText/spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import isFormattingActivated from '../isFormattingActivated'
import getIsFormattingActivated from '../getIsFormattingActivated'
import getStatusBarText, { ENABLED_TEXT, DISABLED_TEXT } from './'

jest.mock('../isFormattingActivated')
jest.mock('../getIsFormattingActivated')

const mockedIsFormattingActivated = isFormattingActivated as jest.Mock
const mockedGetIsFormattingActivated = getIsFormattingActivated as jest.Mock

describe('The `getStatusBarText` helper', () => {
it(`should return \`${ENABLED_TEXT}\` if the formatting is enabled`, () => {
mockedIsFormattingActivated.mockReturnValueOnce(true)
mockedGetIsFormattingActivated.mockReturnValueOnce(true)

const expected = ENABLED_TEXT
const actual = getStatusBarText()
Expand All @@ -16,7 +16,7 @@ describe('The `getStatusBarText` helper', () => {
})

it(`should return \`${DISABLED_TEXT}\` if the formatting is disabled`, () => {
mockedIsFormattingActivated.mockReturnValueOnce(false)
mockedGetIsFormattingActivated.mockReturnValueOnce(false)

const expected = DISABLED_TEXT
const actual = getStatusBarText()
Expand Down
6 changes: 3 additions & 3 deletions src/registerCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
DEFAULT_AFFECTS_CONFIGURATION
} from './constants'
import getConfiguration from './helpers/getConfiguration'
import isFormattingActivated from './helpers/isFormattingActivated'
import getIsFormattingActivated from './helpers/getIsFormattingActivated'

const registerCommand = () =>
commands.registerCommand(COMMAND_NAME, () => {
Expand All @@ -15,15 +15,15 @@ const registerCommand = () =>
'affects',
DEFAULT_AFFECTS_CONFIGURATION
)
const shouldDisableFormatting = isFormattingActivated()
const isFormattingActivated = getIsFormattingActivated()

// Updating the configuration will trigger the `onDidChangeConfiguration`
// handler which will correctly update the text and icon in the status bar.
FORMATTING_SETTINGS.forEach(setting => {
if (affectsConfiguration.includes(setting)) {
editorConfiguration.update(
setting,
!shouldDisableFormatting,
!isFormattingActivated,
ConfigurationTarget.Global
)
}
Expand Down

0 comments on commit cbcc91a

Please sign in to comment.