ronantakizawa/codereview-bench huggingface dataset:
Repository: marktext/marktext
File: src/renderer/prefComponents/spellchecker/index.vue (Vue)

Code before:
<template>
  <div class="pref-spellchecker">
    <h4>Spelling</h4>
    <bool
      description="Enable spell checker (experimental)."
      :bool="spellcheckerEnabled"
      :onChange="handleSpellcheckerEnabled"
    ></bool>
    <separator></separator>
    <bool
      description="Use Hunspell instead of system spell checker on macOS and Windows 10. (Restart required.)
      :bool="spellcheckerIsHunspell"
      :disable="!isOsSpellcheckerSupported || !spellcheckerEnabled"
      :onChange="value => onSelectChange('spellcheckerIsHunspell', value)"
    ></bool>
    <bool
      description="Hide marks on spelling errors."
      :bool="spellcheckerNoUnderline"
      :disable="!spellcheckerEnabled"
      :onChange="value => onSelectChange('spellcheckerNoUnderline', value)"
    ></bool>
    <bool
      description="Automatically detect document language. (Unavailable if Hunspell is used or if spelling errors are not marked.)
      :bool="spellcheckerAutoDetectLanguage"
      :disable="!spellcheckerEnabled"
      :onChange="value => onSelectChange('spellcheckerAutoDetectLanguage', value)"
    ></bool>
    <separator></separator>
    <cur-select
      description="Default language for spell checker."
      :value="spellcheckerLanguage"
      :options="availableDictionaries"
      :disable="!spellcheckerEnabled"
      :onChange="value => onSelectChange('spellcheckerLanguage', value)"
    ></cur-select>
    <div

Review comment (suggestion):
```suggestion
      description="Use Hunspell instead of system spell checker on macOS and Windows 10 (restart required).
```

Code after:
<template>
  <div class="pref-spellchecker">
    <h4>Spelling</h4>
    <bool
      description="Enable spell checker (experimental)."
      :bool="spellcheckerEnabled"
      :onChange="handleSpellcheckerEnabled"
    ></bool>
    <separator></separator>
    <bool
      description="Use Hunspell instead of system spell checker on macOS and Windows 10 (requires restart).
      :bool="spellcheckerIsHunspell"
      :disable="!isOsSpellcheckerSupported || !spellcheckerEnabled"
      :onChange="value => onSelectChange('spellcheckerIsHunspell', value)"
    ></bool>
    <bool
      description="Hide marks for spelling errors."
      :bool="spellcheckerNoUnderline"
      :disable="!spellcheckerEnabled"
      :onChange="value => onSelectChange('spellcheckerNoUnderline', value)"
    ></bool>
    <bool
      v-show="isOsx && !spellcheckerIsHunspell"
      description="Automatically detect document language (requires showing marks for spelling errors).
      :bool="spellcheckerAutoDetectLanguage"
      :disable="!spellcheckerEnabled"
      :onChange="value => onSelectChange('spellcheckerAutoDetectLanguage', value)"
    ></bool>
    <separator></separator>
    <cur-select
      description="Default language for spell checker."
      :value="spellcheckerLanguage"
      :options="availableDictionaries"
      :disable="!spellcheckerEnabled"
      :onChange="value => onSelectChange('spellcheckerLanguage', value)"
    ></cur-select>
Repository: marktext/marktext
File: src/renderer/prefComponents/editor/config.js (JavaScript)

Code before:
import { ENCODING_NAME_MAP } from 'common/encoding'

export const endOfLineOptions = [{
  label: 'Default',
  value: 'default'
}, {
  label: 'Carriage return and line feed (CRLF)',
  value: 'crlf'
}, {
  label: 'Line feed (LF)',
  value: 'lf'
}]

export const trimTrailingNewlineOptions = [{
  label: 'Trim all leading and trailing',
  value: 0
}, {
  label: 'Trim all leading and ensure exactly one trailing',
  value: 1
}, {
  label: 'Trim all leading and all but one trailing',
  value: 2
}, {
  label: 'Do nothing',
  value: 3
}]

export const textDirectionOptions = [{
  label: 'Left to Right',
  value: 'ltr'
}, {
  label: 'Right to Left',
  value: 'rtl'
}]

let defaultEncodingOptions = null
export const getDefaultEncodingOptions = () => {
  if (defaultEncodingOptions) {
    return defaultEncodingOptions
  }

  defaultEncodingOptions = []
  for (const [value, label] of Object.entries(ENCODING_NAME_MAP)) {

Review comment (suggestion):
```suggestion
  label: 'Ensure a single one',
```

Code after:
import { ENCODING_NAME_MAP } from 'common/encoding'

export const endOfLineOptions = [{
  label: 'Default',
  value: 'default'
}, {
  label: 'Carriage return and line feed (CRLF)',
  value: 'crlf'
}, {
  label: 'Line feed (LF)',
  value: 'lf'
}]

export const trimTrailingNewlineOptions = [{
  label: 'Trim all trailing',
  value: 0
}, {
  label: 'Ensure exactly one trailing',
  value: 1
}, {
  label: 'Preserve style of original document',
  value: 2
}, {
  label: 'Do nothing',
  value: 3
}]

export const textDirectionOptions = [{
  label: 'Left to Right',
  value: 'ltr'
}, {
  label: 'Right to Left',
  value: 'rtl'
}]

let defaultEncodingOptions = null
export const getDefaultEncodingOptions = () => {
  if (defaultEncodingOptions) {
    return defaultEncodingOptions
  }

  defaultEncodingOptions = []
  for (const [value, label] of Object.entries(ENCODING_NAME_MAP)) {
Repository: marktext/marktext
File: src/renderer/prefComponents/editor/config.js (JavaScript)

Code before:
import { ENCODING_NAME_MAP } from 'common/encoding'

export const endOfLineOptions = [{
  label: 'Default',
  value: 'default'
}, {
  label: 'Carriage return and line feed (CRLF)',
  value: 'crlf'
}, {
  label: 'Line feed (LF)',
  value: 'lf'
}]

export const trimTrailingNewlineOptions = [{
  label: 'Trim all leading and trailing',
  value: 0
}, {
  label: 'Trim all leading and ensure exactly one trailing',
  value: 1
}, {
  label: 'Trim all leading and all but one trailing',
  value: 2
}, {
  label: 'Do nothing',
  value: 3
}]

export const textDirectionOptions = [{
  label: 'Left to Right',
  value: 'ltr'
}, {
  label: 'Right to Left',
  value: 'rtl'
}]

let defaultEncodingOptions = null
export const getDefaultEncodingOptions = () => {
  if (defaultEncodingOptions) {
    return defaultEncodingOptions
  }

  defaultEncodingOptions = []
  for (const [value, label] of Object.entries(ENCODING_NAME_MAP)) {
    defaultEncodingOptions.push({ label, value })
  }
  return defaultEncodingOptions

Review comment (suggestion):
```suggestion
  label: 'Detect trailing style',
```

Code after:
import { ENCODING_NAME_MAP } from 'common/encoding'

export const endOfLineOptions = [{
  label: 'Default',
  value: 'default'
}, {
  label: 'Carriage return and line feed (CRLF)',
  value: 'crlf'
}, {
  label: 'Line feed (LF)',
  value: 'lf'
}]

export const trimTrailingNewlineOptions = [{
  label: 'Trim all trailing',
  value: 0
}, {
  label: 'Ensure exactly one trailing',
  value: 1
}, {
  label: 'Preserve style of original document',
  value: 2
}, {
  label: 'Do nothing',
  value: 3
}]

export const textDirectionOptions = [{
  label: 'Left to Right',
  value: 'ltr'
}, {
  label: 'Right to Left',
  value: 'rtl'
}]

let defaultEncodingOptions = null
export const getDefaultEncodingOptions = () => {
  if (defaultEncodingOptions) {
    return defaultEncodingOptions
  }

  defaultEncodingOptions = []
  for (const [value, label] of Object.entries(ENCODING_NAME_MAP)) {
    defaultEncodingOptions.push({ label, value })
  }
  return defaultEncodingOptions
Repository: marktext/marktext
File: src/renderer/prefComponents/imageUploader/index.vue (Vue)

Code before:
    },
    imageBed: {
      get: function () {
        return this.$store.state.preferences.imageBed
      }
    },
    prefGithubToken: {
      get: function () {
        return this.$store.state.preferences.githubToken
      }
    },
    prefCliScript: {
      get: function () {
        return this.$store.state.preferences.cliScript
      }
    },
    githubDisable () {
      return !this.githubToken || !this.github.owner || !this.github.repo
    },
    cliScriptDisable () {
      if (!this.cliScript) {
        return true
      }
      try {
        const stat = statSync(this.cliScript)
        return !stat.isFile() || (stat.mode & (S_IXUSR | S_IXGRP | S_IXOTH)) === 0
      } catch (err) {
        // err ignored
        return true
      }
    }
  },
  watch: {
    imageBed: function (value, oldValue) {
      if (value !== oldValue) {
        this.github = value.github
      }
    }
  },
  created () {
    this.$nextTick(() => {
      this.github = this.imageBed.github
      this.githubToken = this.prefGithubToken
      this.cliScript = this.prefCliScript

      if (services.hasOwnProperty(this.currentUploader)) {
        services[this.currentUploader].agreedToLegalNotices = true
      }
    })
  },
  methods: {

Review comment (suggestion):
Could you please move the code inside try/catch to `utils/filesystem.js` to separate fronted and "backend" stuff. Like `isFileExecutable` and negate the result.

Code after:
      get: function () {
        return this.$store.state.preferences.imageBed
      }
    },
    prefGithubToken: {
      get: function () {
        return this.$store.state.preferences.githubToken
      }
    },
    prefCliScript: {
      get: function () {
        return this.$store.state.preferences.cliScript
      }
    },
    githubDisable () {
      return !this.githubToken || !this.github.owner || !this.github.repo
    },
    cliScriptDisable () {
      if (!this.cliScript) {
        return true
      }
      return !isFileExecutable(this.cliScript)
    }
  },
  watch: {
    imageBed: function (value, oldValue) {
      if (value !== oldValue) {
        this.github = value.github
      }
    }
  },
  created () {
    this.$nextTick(() => {
      this.github = this.imageBed.github
      this.githubToken = this.prefGithubToken
      this.cliScript = this.prefCliScript

      if (services.hasOwnProperty(this.currentUploader)) {
        services[this.currentUploader].agreedToLegalNotices = true
      }
    })
  },
  methods: {
    isValidUploaderService (name) {
      return isValidService(name)
    },
    getServiceNameById (id) {
      const service = services[id]
      return service ? service.name : id
    },
    open (link) {
Repository: marktext/marktext
File: src/main/menu/actions/edit.js (JavaScript)

Code before:
import path from 'path'
import { ipcMain, BrowserWindow } from 'electron'
import log from 'electron-log'
import { searchFilesAndDir } from '../../utils/imagePathAutoComplement'

ipcMain.on('mt::ask-for-image-auto-path', (e, { pathname, src, id }) => {
  const win = BrowserWindow.fromWebContents(e.sender)
  if (!src || src !== 'string') {
    win.webContents.send(`mt::response-of-image-path-${id}`, [])
    return
  }

  if (src.endsWith('/') || src.endsWith('\\') || src.endsWith('.')) {
    return win.webContents.send(`mt::response-of-image-path-${id}`, [])
  }
  const fullPath = path.isAbsolute(src) ? src : path.join(path.dirname(pathname), src)
  const dir = path.dirname(fullPath)
  const searchKey = path.basename(fullPath)
  searchFilesAndDir(dir, searchKey)
    .then(files => {
      return win.webContents.send(`mt::response-of-image-path-${id}`, files)
    })
    .catch(err => {
      log.error(err)
      return win.webContents.send(`mt::response-of-image-path-${id}`, [])
    })
})

export const edit = (win, type) => {
  if (win && win.webContents) {
    win.webContents.send('mt::editor-edit-action', type)
  }
}

Review comment (suggestion):
Do you lost `typeof` ?

`typeof src !== 'string'`

Code after:
import path from 'path'
import { ipcMain, BrowserWindow } from 'electron'
import log from 'electron-log'
import { searchFilesAndDir } from '../../utils/imagePathAutoComplement'

ipcMain.on('mt::ask-for-image-auto-path', (e, { pathname, src, id }) => {
  const win = BrowserWindow.fromWebContents(e.sender)
  if (!src || typeof src !== 'string') {
    win.webContents.send(`mt::response-of-image-path-${id}`, [])
    return
  }

  if (src.endsWith('/') || src.endsWith('\\') || src.endsWith('.')) {
    return win.webContents.send(`mt::response-of-image-path-${id}`, [])
  }
  const fullPath = path.isAbsolute(src) ? src : path.join(path.dirname(pathname), src)
  const dir = path.dirname(fullPath)
  const searchKey = path.basename(fullPath)
  searchFilesAndDir(dir, searchKey)
    .then(files => {
      return win.webContents.send(`mt::response-of-image-path-${id}`, files)
    })
    .catch(err => {
      log.error(err)
      return win.webContents.send(`mt::response-of-image-path-${id}`, [])
    })
})

export const edit = (win, type) => {
  if (win && win.webContents) {
    win.webContents.send('mt::editor-edit-action', type)
  }
}
Repository: marktext/marktext
File: src/muya/lib/parser/render/plantuml.js (JavaScript)

Code before:
import zlib from 'zlib'
import _ from 'underscore'
import { toHTML, h } from './snabbdom'

const PLANTUML_URL = 'https://www.plantuml.com/plantuml'

function replaceChar (tableIn, tableOut, char) {
  const charIndex = tableIn.indexOf(char)
  return tableOut[charIndex]
}

function maketrans (tableIn, tableOut, value) {
  return [...value].map(i => replaceChar(tableIn, tableOut, i)).join('')
}

export default class Diagram {
  encodedInput = '';

  /**
   * Builds a Diagram object storing the encoded input value
   */
  static parse (input) {
    const diagram = new Diagram()
    diagram.encodedInput = Diagram.encode(input)
    return diagram
  }


Review comment (suggestion):
It's better to not use `underscore`, we maybe remove `underscore` from the dependences in the future.

Code after:
import zlib from 'zlib'
import { toHTML, h } from './snabbdom'

const PLANTUML_URL = 'https://www.plantuml.com/plantuml'

function replaceChar (tableIn, tableOut, char) {
  const charIndex = tableIn.indexOf(char)
  return tableOut[charIndex]
}

function maketrans (tableIn, tableOut, value) {
  return [...value].map(i => replaceChar(tableIn, tableOut, i)).join('')
}

export default class Diagram {
  encodedInput = '';

  /**
   * Builds a Diagram object storing the encoded input value
   */
  static parse (input) {
    const diagram = new Diagram()
    diagram.encodedInput = Diagram.encode(input)
    return diagram
  }

  /**
Repository: marktext/marktext
File: src/renderer/prefComponents/image/index.vue (Vue)

Code before:
    imageInsertAction: {
      get: function () {
        return this.$store.state.preferences.imageInsertAction
      },
      set: function (value) {
        const type = 'imageInsertAction'
        this.$store.dispatch('SET_SINGLE_PREFERENCE', { type, value })
      }
    },
    FolderPathPlaceholder: {
      get: function () {
        return this.$store.state.preferences.imageFolderPath || ''
      }
    },
    relativeDirectoryNamePlaceholder: {
      get: function () {
        return this.$store.state.preferences.imageRelativeDirectoryName || 'assets'
      }
    }
  },
  methods: {
    openImageFolder () {
      shell.openPath(this.imageFolderPath)
    },
    modifyImageFolderPath (value) {
      return this.$store.dispatch('SET_IMAGE_FOLDER_PATH', value)
    },
    onSelectChange (type, value) {
      this.$store.dispatch('SET_SINGLE_PREFERENCE', { type, value })
    }
  }
}
</script>

<style>
.pref-image {
  & .image-ctrl {
    font-size: 14px;
    margin: 20px 0;
    color: var(--editorColor);
    & label {
      display: block;
      margin: 20px 0;
    }
  }
}
</style>


Review comment (suggestion):
This event commits the path to the main-process and create the directory by default. We have to remove the directory creation in `src/main` and verify that the renderer process creates it if not already exists.

Code after:
    imageInsertAction: {
      get: function () {
        return this.$store.state.preferences.imageInsertAction
      },
      set: function (value) {
        const type = 'imageInsertAction'
        this.$store.dispatch('SET_SINGLE_PREFERENCE', { type, value })
      }
    },
    folderPathPlaceholder: {
      get: function () {
        return this.$store.state.preferences.imageFolderPath || ''
      }
    },
    relativeDirectoryNamePlaceholder: {
      get: function () {
        return this.$store.state.preferences.imageRelativeDirectoryName || 'assets'
      }
    }
  },
  methods: {
    openImageFolder () {
      shell.openPath(this.imageFolderPath)
    },
    modifyImageFolderPath (value) {
      return this.$store.dispatch('SET_IMAGE_FOLDER_PATH', value)
    },
    onSelectChange (type, value) {
      this.$store.dispatch('SET_SINGLE_PREFERENCE', { type, value })
    }
  }
}
</script>

<style>
.pref-image {
  & .image-ctrl {
    font-size: 14px;
    margin: 20px 0;
    color: var(--editorColor);
    & label {
      display: block;
      margin: 20px 0;
    }
  }
}
</style>
Repository: marktext/marktext
File: src/main/menu/templates/view.js (JavaScript)

Code before:
        actions.layout(item, browserWindow, 'showTabBar')
      }
    }, {
      label: 'Toggle Table of Contents',
      id: 'tocMenuItem',
      accelerator: keybindings.getAccelerator('view.toggle-toc'),
      click (_, browserWindow) {
        actions.layout(null, browserWindow, 'rightColumn', 'toc')
      }
    }, {
      type: 'separator'
    }]
  }

  if (global.MARKTEXT_DEBUG) {
    viewMenu.submenu.push({
      label: 'Show Developer Tools',
      accelerator: keybindings.getAccelerator('view.toggle-dev-tools'),
      click (item, focusedWindow) {
        if (focusedWindow) {
          focusedWindow.webContents.toggleDevTools()
        }
      }
    })
    viewMenu.submenu.push({
      label: 'Reload (for Development)',
      accelerator: keybindings.getAccelerator('view.dev-reload'),
      click (item, focusedWindow) {
        if (focusedWindow) {
          ipcMain.emit('window-reload-by-id', focusedWindow.id)
        }
      }
    })
  }

  viewMenu.submenu.push({
    label: 'Reload Images',
    accelerator: keybindings.getAccelerator('view.reload-images'),
    click (item, focusedWindow) {
      if (focusedWindow) {
        ipcMain.emit('invalidate-image-cache-by-id', focusedWindow.id)
      }
    }
  })
  return viewMenu
}


Review comment (bug):
I would prefer `Reload window` because it's only enabled in development/debug mode.

Code after:
        actions.layout(item, browserWindow, 'showTabBar')
      }
    }, {
      label: 'Toggle Table of Contents',
      id: 'tocMenuItem',
      accelerator: keybindings.getAccelerator('view.toggle-toc'),
      click (_, browserWindow) {
        actions.layout(null, browserWindow, 'rightColumn', 'toc')
      }
    }, {
      label: 'Reload Images',
      accelerator: keybindings.getAccelerator('view.reload-images'),
      click (item, focusedWindow) {
        if (focusedWindow) {
          focusedWindow.webContents.send('mt::invalidate-image-cache', {})
        }
      }
    }, {
      type: 'separator'
    }]
  }

  if (global.MARKTEXT_DEBUG) {
    viewMenu.submenu.push({
      label: 'Show Developer Tools',
      accelerator: keybindings.getAccelerator('view.toggle-dev-tools'),
      click (item, focusedWindow) {
        if (focusedWindow) {
          focusedWindow.webContents.toggleDevTools()
        }
      }
    })
    viewMenu.submenu.push({
      label: 'Reload window',
      accelerator: keybindings.getAccelerator('view.dev-reload'),
      click (item, focusedWindow) {
        if (focusedWindow) {
          ipcMain.emit('window-reload-by-id', focusedWindow.id)
        }
      }
    })
  }

  return viewMenu
}
Repository: marktext/marktext
File: src/main/menu/templates/view.js (JavaScript)

Code before:
      type: 'separator'
    }]
  }

  if (global.MARKTEXT_DEBUG) {
    viewMenu.submenu.push({
      label: 'Show Developer Tools',
      accelerator: keybindings.getAccelerator('view.toggle-dev-tools'),
      click (item, focusedWindow) {
        if (focusedWindow) {
          focusedWindow.webContents.toggleDevTools()
        }
      }
    })
    viewMenu.submenu.push({
      label: 'Reload (for Development)',
      accelerator: keybindings.getAccelerator('view.dev-reload'),
      click (item, focusedWindow) {
        if (focusedWindow) {
          ipcMain.emit('window-reload-by-id', focusedWindow.id)
        }
      }
    })
  }

  viewMenu.submenu.push({
    label: 'Reload Images',
    accelerator: keybindings.getAccelerator('view.reload-images'),
    click (item, focusedWindow) {
      if (focusedWindow) {
        ipcMain.emit('invalidate-image-cache-by-id', focusedWindow.id)
      }
    }
  })
  return viewMenu
}


Review comment (bug):
You can add this directly under `Toggle Table of Contents` and then append a separator (between image reload and debug entries).

Code after:
      label: 'Reload Images',
      accelerator: keybindings.getAccelerator('view.reload-images'),
      click (item, focusedWindow) {
        if (focusedWindow) {
          focusedWindow.webContents.send('mt::invalidate-image-cache', {})
        }
      }
    }, {
      type: 'separator'
    }]
  }

  if (global.MARKTEXT_DEBUG) {
    viewMenu.submenu.push({
      label: 'Show Developer Tools',
      accelerator: keybindings.getAccelerator('view.toggle-dev-tools'),
      click (item, focusedWindow) {
        if (focusedWindow) {
          focusedWindow.webContents.toggleDevTools()
        }
      }
    })
    viewMenu.submenu.push({
      label: 'Reload window',
      accelerator: keybindings.getAccelerator('view.dev-reload'),
      click (item, focusedWindow) {
        if (focusedWindow) {
          ipcMain.emit('window-reload-by-id', focusedWindow.id)
        }
      }
    })
  }

  return viewMenu
}
Repository: matplotlib/matplotlib
File: lib/matplotlib/_docstring.py (Python)

Code before:
import inspect

from . import _api


def kwdoc(text):
    """
    Decorator for adding kwdoc documentation to Artist property setters.

    The given text is stored in a privat variable ``_kwdoc`` on the method.
    It is used for generating the kwdoc list for artists, which we
    auto-generate through docstring interpolation, e.g. via
    ``%(Line2D:kwdoc)s``.

    The text should contain the supported types as well as the default value
    if applicable, e.g.:

        @_docstring.kwdoc("bool, default: :rc:`text.usetex`")
        def set_usetex(self, usetex):

    """
    def decorator(func):
        func._kwdoc = text
        return func
    return decorator


class Substitution:
    """
    A decorator that performs %-substitution on an object's docstring.


Review comment (suggestion):
This name and description is still unclear to me, even after you explained it to me.  I think the name should be more descriptive, and the docstring here more explicit about what problem this solves.  

Code after:
import inspect

from . import _api


def kwarg_doc(text):
    """
    Decorator for defining the kwdoc documentation of artist properties.

    This decorator can be applied to artist property setter methods.
    The given text is stored in a privat attribute ``_kwarg_doc`` on
    the method.  It is used to overwrite auto-generated documentation
    in the *kwdoc list* for artists. The kwdoc list is used to document
    ``**kwargs`` when they are properties of an artist. See e.g. the
    ``**kwargs`` section in `.Axes.text`.

    The text should contain the supported types as well as the default value
    if applicable, e.g.:

        @_docstring.kwarg_doc("bool, default: :rc:`text.usetex`")
        def set_usetex(self, usetex):

    See Also
    --------
    matplotlib.artist.kwdoc

    """
    def decorator(func):
        func._kwarg_doc = text
        return func
    return decorator