Code Monkey home page Code Monkey logo

atom-jsfmt's Introduction

atom-jsfmt

David

atom-jsfmt is a jsfmt plugin for the Atom text editor. jsfmt is really good at formatting, searching, and rewriting javascript. It's pretty nifty.

atom-jsfmt in action

What does it do?

  • Format your code: Run the Jsfmt: Format command to keep your code well-styled.
  • Format on save: atom-jsfmt will auto-format your javascript every time you save, so you don't have to think about it.

How do I get it?

Installation can be done from Atom's package browser (just search for atom-jsfmt). You can also use the apm command line installer:

apm install atom-jsfmt

How do I tweak the formatting?

Although the default style guide is pretty good, you may find yourself wanting to tweak the formatting. atom-jsfmt looks for the closest .jsfmtrc file before formatting (you can read more about them here). It checks the directory of the current file, and keeps moving up directories until it finds something.

For example, if you like your code indented four spaces, your .jsfmtrc might look like this:

{
    "indent": {
        "value": "    "
    }
}

Options

  • Show Errors: Whether or not you want to see error messages. You probably do. This is set to true by default.
  • Format On Save: Whether or not you automatically want to format your javascript files when you save. Defaults to true.

To do

  • Look for .jsfmtrc files in all the places that the command line tool looks (like /etc/.jsfmtrc or ~/.jsfmtrc).
  • Add searching / rewriting functionality
  • Flag lines with errors

Credit

  • jsfmt is written and maintained by the good folks at rdio.

Changelog

The changelog can be viewed here.

License

Atom-jsfmt is licensed under the MIT license, which can be viewed here.

atom-jsfmt's People

Contributors

andrewn avatar mikaa123 avatar ontofractal avatar salemhilal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

atom-jsfmt's Issues

Uncaught TypeError: Cannot read property 'length' of null

[Enter steps to reproduce below:]

Same as #12

Atom Version: 1.0.0
System: Mac OS X 10.10.3
Thrown From: atom-jsfmt package, v0.8.2

Stack Trace

Uncaught TypeError: Cannot read property 'length' of null

At /Applications/Atom.app/Contents/Resources/app.asar/src/pane.js:762

TypeError: Cannot read property 'length' of null
  at Function.module.exports.JsfmtRunner.errorToLineNumber (/Users/lucas/.atom/packages/atom-jsfmt/lib/jsfmtRunner.coffee:123:8)
  at Function.module.exports.JsfmtRunner.errorToMessage (/Users/lucas/.atom/packages/atom-jsfmt/lib/jsfmtRunner.coffee:95:13)
  at Function.module.exports.JsfmtRunner.format (/Users/lucas/.atom/packages/atom-jsfmt/lib/jsfmtRunner.coffee:75:14)
  at /Users/lucas/.atom/packages/atom-jsfmt/lib/jsfmtRunner.coffee:55:10
  at Emitter.module.exports.Emitter.emit (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/event-kit/lib/emitter.js:82:11)
  at TextBuffer.module.exports.TextBuffer.saveAs (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/text-buffer/lib/text-buffer.js:985:20)
  at TextBuffer.module.exports.TextBuffer.save (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/text-buffer/lib/text-buffer.js:978:19)
  at TextEditor.module.exports.TextEditor.save (/Applications/Atom.app/Contents/Resources/app.asar/src/text-editor.js:579:26)
  at Pane.module.exports.Pane.saveItem (/Applications/Atom.app/Contents/Resources/app.asar/src/pane.js:523:18)
  at Pane.module.exports.Pane.saveActiveItem (/Applications/Atom.app/Contents/Resources/app.asar/src/pane.js:506:19)
  at Workspace.module.exports.Workspace.saveActivePaneItem (/Applications/Atom.app/Contents/Resources/app.asar/src/workspace.js:592:35)
  at atom-workspace.atom.commands.add.core:save (/Applications/Atom.app/Contents/Resources/app.asar/src/workspace-element.js:311:30)
  at CommandRegistry.module.exports.CommandRegistry.handleCommandEvent (/Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:241:29)
  at /Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:3:61
  at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:520:16)
  at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:355:22)
  at HTMLDocument.module.exports.WindowEventHandler.onKeydown (/Applications/Atom.app/Contents/Resources/app.asar/src/window-event-handler.js:180:20)

Commands

     -5:31.4.0 core:paste (input.hidden-input)
     -5:30.7.0 core:undo (input.hidden-input)
     -5:30.1.0 core:paste (input.hidden-input)
  3x -5:29.4.0 core:backspace (input.hidden-input)
     -5:28.4.0 editor:move-to-first-character-of-line (input.hidden-input)
     -5:27.7.0 editor:move-to-end-of-screen-line (input.hidden-input)
     -5:26.3.0 core:move-left (input.hidden-input)
     -5:25 core:paste (input.hidden-input)
     -5:24.2.0 core:save (input.hidden-input)
     -4:11.4.0 editor:newline-below (input.hidden-input)
     -4:11.3.0 core:paste (input.hidden-input)
     -4:02.8.0 core:save (input.hidden-input)
     -3:12.5.0 core:backspace (input.hidden-input)
  2x -3:12.1.0 core:save (input.hidden-input)
     -1:27.6.0 core:copy (input.hidden-input)
  2x -0:07.0 core:save (input.hidden-input)

Config

{
  "core": {
    "ignoredNames": [
      ".git",
      ".svn",
      ".DS_Store"
    ],
    "themes": [
      "isotope-ui",
      "afterglow-like"
    ]
  },
  "atom-jsfmt": {
    "showErrors": false
  }
}

Installed Packages

# User
Sublime-Style-Column-Selection, v1.3.0
afterglow-like, v0.2.1
atom-jsfmt, v0.8.2
build, v0.39.0
color-picker, v2.0.7
command-logger, v0.23.0
editor-stats, v0.17.0
file-icons, v1.5.8
isotope-ui, v2.4.2
language-jade, v0.4.0
linter, v1.1.0
linter-coffeelint, v0.3.2
linter-eslint, v1.0.11
linter-jshint, v0.1.7
minimap, v4.10.1
motepair, v0.20.0
regex-railroad-diagram, v0.8.1
travis-ci-status, v0.15.1
wercker-status, v1.0.5

# Dev
No dev packages

Getting error on each document save

Everytime I save an edited document I get following error logged and nothing happens. Don't know if it means that jsfmt wasn't found or the file I'm currently editing. jsfmt installed globally (-g option).

Uncaught Error: spawn ENOENT events.js:82
execvp(): No such file or directory
 /Users/daniel/.atom/packages/atom-jsfmt/lib/jsfmt.js:20

Failed to load the atom-jsfmt package

After updating to 0.8.4 I get the following error.

Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self'".

I'm using Atom 1.5.3 on Windows 7 64 Bit. Please find the error report attached.
error-report.txt

Thanks for the great plugin.
Christian

formatOnSave doesnt always format

It seems the format action may be taken after the save

I fixed it by changing the

    editor.getBuffer().on 'saved'

into a

    editor.getBuffer().onWillSave =>

Uncaught TypeError: Cannot read property 'length' of null

  1. Edit any file + save
  2. error occurs

Atom Version: 0.210.0
System: Mac OS X 10.10.3
Thrown From: atom-jsfmt package, v0.8.1

Stack Trace

Uncaught TypeError: Cannot read property 'length' of null

At /Applications/Atom.app/Contents/Resources/app.asar/src/pane.js:762

TypeError: Cannot read property 'length' of null
  at Function.module.exports.JsfmtRunner.errorToLineNumber (/Users/lucas/.atom/packages/atom-jsfmt/lib/jsfmtRunner.coffee:123:15)
  at Function.module.exports.JsfmtRunner.errorToMessage (/Users/lucas/.atom/packages/atom-jsfmt/lib/jsfmtRunner.coffee:95:13)
  at Function.module.exports.JsfmtRunner.format (/Users/lucas/.atom/packages/atom-jsfmt/lib/jsfmtRunner.coffee:85:28)
  at /Users/lucas/.atom/packages/atom-jsfmt/lib/jsfmtRunner.coffee:55:10
  at Emitter.module.exports.Emitter.emit (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/event-kit/lib/emitter.js:82:11)
  at TextBuffer.module.exports.TextBuffer.saveAs (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/text-buffer/lib/text-buffer.js:985:20)
  at TextBuffer.module.exports.TextBuffer.save (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/text-buffer/lib/text-buffer.js:978:19)
  at TextEditor.module.exports.TextEditor.save (/Applications/Atom.app/Contents/Resources/app.asar/src/text-editor.js:579:26)
  at Pane.module.exports.Pane.saveItem (/Applications/Atom.app/Contents/Resources/app.asar/src/pane.js:523:18)
  at Pane.module.exports.Pane.saveActiveItem (/Applications/Atom.app/Contents/Resources/app.asar/src/pane.js:506:19)
  at Workspace.module.exports.Workspace.saveActivePaneItem (/Applications/Atom.app/Contents/Resources/app.asar/src/workspace.js:594:35)
  at atom-workspace.atom.commands.add.core:save (/Applications/Atom.app/Contents/Resources/app.asar/src/workspace-element.js:317:30)
  at CommandRegistry.module.exports.CommandRegistry.handleCommandEvent (/Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:238:29)
  at /Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:3:61
  at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:520:16)
  at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:355:22)
  at HTMLDocument.module.exports.WindowEventHandler.onKeydown (/Applications/Atom.app/Contents/Resources/app.asar/src/window-event-handler.js:180:20)

Commands

     -0:01.5.0 core:save (atom-text-editor.editor.is-focused)

Config

{
  "core": {
    "ignoredNames": [
      ".git",
      ".svn",
      ".DS_Store"
    ],
    "themes": [
      "isotope-ui",
      "afterglow-like"
    ],
    "destroyEmptyPanes": false
  }
}

Installed Packages

# User
Sublime-Style-Column-Selection, v1.3.0
afterglow-like, v0.2.1
atom-jsfmt, v0.8.1
build, v0.38.0
color-picker, v2.0.5
command-logger, v0.23.0
editor-stats, v0.17.0
file-icons, v1.5.7
isotope-ui, v2.4.0
language-jade, v0.4.0
linter, v0.12.7
linter-coffeelint, v0.3.2
linter-jshint, v0.1.6
minimap, v4.10.0
motepair, v0.20.0
regex-railroad-diagram, v0.8.0
travis-ci-status, v0.15.1
wercker-status, v1.0.5

# Dev
No dev packages

Support .jsfmtrc files

Your TODO in the README

Allow for input of custom rules

probably covers this, but, thought I'd call it out specifically ๐Ÿ˜ธ

Thanks

Uncaught TypeError: Cannot read property 'close' of null

[Enter steps to reproduce below:]

  1. ...
  2. ...

Atom Version: 1.6.2
System: Mac OS X 10.11.1
Thrown From: atom-jsfmt package, v0.8.5

Stack Trace

Uncaught TypeError: Cannot read property 'close' of null

At /Users/zhangxing/.atom/packages/atom-jsfmt/lib/jsfmtRunner.coffee:64

TypeError: Cannot read property 'close' of null
    at Function.module.exports.JsfmtRunner.format (/Users/zhangxing/.atom/packages/atom-jsfmt/lib/jsfmtRunner.coffee:64:18)
    at Function.module.exports.JsfmtRunner.formatCurrent (/Users/zhangxing/.atom/packages/atom-jsfmt/lib/jsfmtRunner.coffee:110:6)
    at atom-workspace.<anonymous> (/Users/zhangxing/.atom/packages/atom-jsfmt/lib/jsfmtRunner.coffee:25:34)
    at CommandRegistry.module.exports.CommandRegistry.handleCommandEvent (/Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:260:29)
    at /Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:3:61
    at CommandPaletteView.module.exports.CommandPaletteView.confirmed (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/command-palette/lib/command-palette-view.js:183:32)
    at CommandPaletteView.module.exports.SelectListView.confirmSelection (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/atom-space-pen-views/lib/select-list-view.js:338:21)
    at space-pen-div.atom.commands.add.core:confirm (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/atom-space-pen-views/lib/select-list-view.js:109:19)
    at CommandRegistry.module.exports.CommandRegistry.handleCommandEvent (/Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:260:29)
    at /Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:3:61
    at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:580:16)
    at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:388:22)
    at WindowEventHandler.module.exports.WindowEventHandler.handleDocumentKeydown (/Applications/Atom.app/Contents/Resources/app.asar/src/window-event-handler.js:97:36)
    at HTMLDocument.<anonymous> (/Applications/Atom.app/Contents/Resources/app.asar/src/window-event-handler.js:3:61)

Commands

  2x -1:05.8.0 core:move-down (atom-text-editor.editor.mini.is-focused)
  2x -1:04.7.0 core:move-up (atom-text-editor.editor.mini.is-focused)
     -1:04.1.0 core:confirm (atom-text-editor.editor.mini.is-focused)
     -1:04.1.0 jsfmt:execute (atom-text-editor.editor)
     -0:19.2.0 command-palette:toggle (atom-text-editor.editor.is-focused)
     -0:17.6.0 core:confirm (atom-text-editor.editor.mini.is-focused)
     -0:17.6.0 jsfmt:execute (atom-text-editor.editor)
     -0:11.6.0 core:select-all (atom-text-editor.editor.is-focused)
     -0:11.4.0 core:copy (atom-text-editor.editor.is-focused)
  2x -0:11 core:close (atom-text-editor.editor.is-focused)
     -0:05.2.0 application:new-file (atom-text-editor.editor.is-focused)
     -0:04.9.0 core:paste (atom-text-editor.editor.is-focused)
     -0:03.7.0 command-palette:toggle (atom-text-editor.editor.is-focused)
     -0:01.5.0 core:move-down (atom-text-editor.editor.mini.is-focused)
     -0:01.2.0 core:confirm (atom-text-editor.editor.mini.is-focused)
     -0:01.2.0 atom-jsfmt:format (atom-text-editor.editor)

Config

{
  "core": {
    "disabledPackages": [
      "about",
      "archive-view",
      "autocomplete-atom-api",
      "language-coffee-script",
      "language-csharp",
      "language-ruby-on-rails",
      "atom-jsfmt",
      "jsfmt"
    ]
  }
}

Installed Packages

# User
No installed packages

# Dev
No dev packages

Plugins don't seems to be working

Hi,

I recently tried to use Atom instead of Sublime and I had an existing .jsfmtrc file that was using esformatter-quotes and esformatter-braces plugins. With atom-jsfmt I keep getting Cannot find module 'esformatter-quotes' error. Is this because plugins are not supported?

Thanks!

Cannot be installed via command line

$ apm install atom-jsfmt
Installing atom-jsfmt to /Users/stevemao/.atom/packages โœ—
No available version compatible with the installed Atom version: 0.146.0

npm: '2.1.6'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.