Prettier-atom: possibility of data loss in conjunction with `autosave` plugin

Created on 12 Sep 2017  路  1Comment  路  Source: prettier/prettier-atom

Using formatOnSaveOptions in conjunction with the autosave plugin leads to saving and empty file under some circumstances with the new C++ text buffer implementation (from Atom 1.19.0 on). Particularly this happens when editor.setTextInBufferRange is called while a save is in progress.

I will also open an issue in atom/atom since this seems to be a regression.

Reproduction steps

  1. Install prettier-atom and enable formatOnSaveOptions
  2. Open autosave's settings and enable it
  3. Open a javascript file
  4. Change it in a way that it needs to be formatted (e.g. remove a semicolon)
  5. Hit cmd-w to close the window w/o saving.

What Happens (since Atom 1.19.0)

The file will be saved empty

atom-prettier-1 19 7

What Should Happen (used to work in Atom 1.18.0)

The file should be formatted and saved.

atom-prettier-1 18

Prettier:Debug for Atom 1.19.7 (new C++ text buffer implementation)

Atom version: 1.19.7
prettier-atom version: 0.38.0
prettier version: 1.6.1
prettier-eslint version: 6.4.3
prettier-atom configuration: {
  "formatOnSaveOptions": {
    "enabled": true,
    "showInStatusBar": true,
    "respectEslintignore": true,
    "javascriptScopes": [
      "source.js",
      "source.jsx",
      "source.js.jsx",
      "source.babel",
      "source.js-semantic",
      "text.html.basic",
      "text.html.vue"
    ],
    "typescriptScopes": [
      "source.ts",
      "source.tsx",
      "source.ts.tsx"
    ],
    "cssScopes": [
      "source.css",
      "source.less",
      "source.css.less",
      "source.scss",
      "source.css.scss"
    ],
    "jsonScopes": [
      "source.json"
    ],
    "graphQlScopes": [
      "source.graphql"
    ],
    "excludedGlobs": [],
    "whitelistedGlobs": [],
    "isDisabledIfNotInPackageJson": false
  },
  "prettierOptions": {
    "trailingComma": "all",
    "singleQuote": false,
    "bracketSpacing": true,
    "semi": true,
    "useTabs": false,
    "jsxBracketSameLine": false,
    "printWidth": 80,
    "tabWidth": "auto",
    "parser": "babylon"
  },
  "useEslint": false,
  "useEditorConfig": true,
  "prettierEslintOptions": {
    "prettierLast": false
  }
}

Prettier:Debug for Atom 1.18.0 (old javascript text buffer implementation)

Atom version: 1.18.0
prettier-atom version: 0.38.0
prettier version: 1.6.1
prettier-eslint version: 6.4.3
prettier-atom configuration: {
  "formatOnSaveOptions": {
    "enabled": true,
    "showInStatusBar": true,
    "respectEslintignore": true,
    "javascriptScopes": [
      "source.js",
      "source.jsx",
      "source.js.jsx",
      "source.babel",
      "source.js-semantic",
      "text.html.basic",
      "text.html.vue"
    ],
    "typescriptScopes": [
      "source.ts",
      "source.tsx",
      "source.ts.tsx"
    ],
    "cssScopes": [
      "source.css",
      "source.less",
      "source.css.less",
      "source.scss",
      "source.css.scss"
    ],
    "jsonScopes": [
      "source.json"
    ],
    "graphQlScopes": [
      "source.graphql"
    ],
    "excludedGlobs": [],
    "whitelistedGlobs": [],
    "isDisabledIfNotInPackageJson": false
  },
  "prettierOptions": {
    "trailingComma": "all",
    "singleQuote": false,
    "bracketSpacing": true,
    "semi": true,
    "useTabs": false,
    "jsxBracketSameLine": false,
    "printWidth": 80,
    "tabWidth": "auto",
    "parser": "babylon"
  },
  "useEslint": false,
  "useEditorConfig": true,
  "prettierEslintOptions": {
    "prettierLast": false
  }
}

bug

Most helpful comment

This is fixed on the master branch of Atom.

>All comments

This is fixed on the master branch of Atom.

Was this page helpful?
0 / 5 - 0 ratings