ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

ESLint-Formatter

by TheSavior ALL Trending

Sublime Text 3 Plugin to Autoformat with Eslint

Details

Installs

  • Total 41K
  • Win 15K
  • Mac 19K
  • Linux 7K
Nov 27 Nov 26 Nov 25 Nov 24 Nov 23 Nov 22 Nov 21 Nov 20 Nov 19 Nov 18 Nov 17 Nov 16 Nov 15 Nov 14 Nov 13 Nov 12 Nov 11 Nov 10 Nov 9 Nov 8 Nov 7 Nov 6 Nov 5 Nov 4 Nov 3 Nov 2 Nov 1 Oct 31 Oct 30 Oct 29 Oct 28 Oct 27 Oct 26 Oct 25 Oct 24 Oct 23 Oct 22 Oct 21 Oct 20 Oct 19 Oct 18 Oct 17 Oct 16 Oct 15 Oct 14 Oct 13
Windows 0 4 8 3 5 3 5 6 8 6 5 5 2 4 4 8 4 7 5 2 3 7 3 3 6 8 7 5 3 6 6 6 4 5 4 3 10 2 12 6 2 9 5 5 11 3
Mac 2 5 6 8 9 2 3 7 6 8 5 4 5 3 3 10 3 7 6 3 0 4 7 14 13 9 4 2 3 5 6 10 8 3 2 4 7 8 4 7 1 5 5 2 7 7
Linux 0 10 5 2 2 3 2 3 5 0 0 1 2 1 2 2 3 8 3 2 4 3 2 3 0 4 4 2 2 4 4 3 3 1 1 1 6 2 4 3 2 2 2 2 3 6

Readme

Source
raw.​githubusercontent.​com

ESLint-Formatter for Sublime Text 3

Sublime Text 3 Plugin to autoformat your javascript code according to the ESLint configuration files you already have.

This plugin formats but does not lint your code. To also enable linting, use this plugin in conjuction with SublimeLinter-eslint.

Installation

Linter installation

This Sublime Text Plugin depends on a valid installation of eslint version 3 or higher. To install eslint, follow the getting started guide: http://eslint.org/docs/user-guide/getting-started.

Plugin installation

Please use Package Control to install the linter plugin. This will ensure that the plugin will be updated when new versions are available. If you want to install from source so you can modify the source code, you probably know what you are doing so we won’t cover that here.

To install via Package Control, do the following:

  1. Within Sublime Text, bring up the Command Palette and type install. Among the commands you should see Package Control: Install Package. If that command is not highlighted, use the keyboard or mouse to select it. There will be a pause of a few seconds while Package Control fetches the list of available plugins.

  2. When the plugin list appears, type eslint format. Among the entries you should see ESLint-Formatter. If that entry is not highlighted, use the keyboard or mouse to select it.

Commands

Command palette:

  • ESLintFormatter: Format this file

Shortcut key:

  • Linux/Windows: [Ctrl + Shift + H]
  • Mac: [Cmd + Shift + H]

Behavior

The formatting will be applied to the last saved state of a file, not the current buffer. If not using the format_on_save: true option, you have to save your file first and then run the command.

Settings

By default, ESLintFormatter will supply the following settings:

Error: language “jsonc” is not supported
{
  // The Nodejs installation path
  // If these are false, we'll invoke the eslint binary directly.
  "node_path": {
    "windows": "node.exe",
    "linux": "/usr/bin/nodejs",
    "osx": "/usr/local/bin/node"
  },

  // The location to search for a locally installed eslint package.
  // These are all relative paths to a project's directory.
  // If this is not found or are false, it will try to fallback to a global package
  // (see 'eslint_path' below)
  "local_eslint_path": {
    "windows": "node_modules/eslint/bin/eslint.js",
    "linux": "node_modules/.bin/eslint",
    "osx": "node_modules/.bin/eslint"
  },

  // The location of the globally installed eslint package to use as a fallback
  "eslint_path": {
    "windows": "%APPDATA%/npm/node_modules/eslint/bin/eslint",
    "linux": "/usr/bin/eslint",
    "osx": "/usr/local/bin/eslint"
  },

  // Specify this path to an eslint config file to override the default behavior.
  // Passed to eslint as --config. Read more here:
  // http://eslint.org/docs/user-guide/command-line-interface#c---config
  // If an absolute path is provided, it will use as is.
  // Else, it will look for the file in the root of the project directory.
  // Failing either, it will skip the config file
  "config_path": "",

  // Pass additional arguments to eslint.
  //
  // Each command should be a string where it supports the following replacements:
  //   $project_path - The path to the projects root folder
  //
  // Example:
  //   ["--parser-options={\"tsconfigRootDir\": \"$project_path\"}"]
  "extra_args": [],

  // Automatically format when a file is saved.
  "format_on_save": false,

  // Use --fix-to-stdout, --stdin, and --stdin-filename to update the file if using eslint_d.
  // See https://github.com/mantoni/eslint_d.js#automatic-fixing
  "fix_to_stdout": false,

  // Only attempt to format files with whitelisted extensions on save.
  // Leave empty to disable the check
  "format_on_save_extensions": [
    "js",
    "jsx",
    "es",
    "es6",
    "babel"
  ]
}
  • Modify any settings within the Preferences -> Package Settings -> ESLint-Formatter -> Settings - User file.

Project-specific settings override

To override global plugin configuration for a specific project, add a settings object with a ESLint-Formatter key in your .sublime-project. This file is accessible via Project -> Edit Project.

For example:

{
  "folders": [
    {
      "path": "."
    }
  ],
  "settings": {
    "ESLint-Formatter": {
      "format_on_save": true
    }
  }
}

Performance

If you experience performance issues, it may be worth taking a look at eslint_d. You can modify the settings to point to the eslint_d binary instead of eslint.

For example:

{
  "local_eslint_path": {
    "osx": "node_modules/.bin/eslint_d"
  }
}

Contributing

If you find any bugs feel free to report them here.

Pull requests are also encouraged.