bcomnes / sublime-standard-format

:sparkles: Runs standard --fix against the javascript in your ST3 window on save or manually.
https://packagecontrol.io/packages/StandardFormat
MIT License
60 stars 21 forks source link

How to ignore a file? #41

Closed nerdpad closed 4 years ago

nerdpad commented 8 years ago

How do I ignore a file from getting auto formatted?

I have r.js build file which begins with (. After format a semicolon is added ;(, which causes r.js to break.

DoomyTheFroomy commented 8 years ago

@NerdPad I have the same problem, normally excludes would be the setting property, but it does not work, all my json files are also formatted:

{
    "PATH": [],
    "command": [
        "standard-format",
        "--stdin"
    ],
    "excludes": [
        "json"
    ],
    "extensions":[
        "js"
    ],
    "format_on_save": true,
    "loud_error": false
}
denizdogan commented 8 years ago

@DoomyTheFroomy I can't reproduce the issue with your exact configuration. Are you using standard-format version 2.2.2?

DoomyTheFroomy commented 8 years ago

@denizdogan just update to 2.2.2, but still no change. Btw. it brings only error if your json file starts with a bracket, e.g.:

[
  {
    "attribute": "value"
  },
  {
    "attribute": "value"
  } 
]
denizdogan commented 8 years ago

Hmm, looking at the source code there is indeed some strage behavior. Whenever the user saves a file, the plugin has a couple of rules to determine whether the file is JavaScript or not, see the function is_javascript: https://github.com/bcomnes/sublime-standard-format/blob/master/standard-format.py#L60

I suspect that your file is being detected as JavaScript when you open it and the syntax is automatically set to "JavaScript" or something similar. Your file is actually invalid JSON, it must always start with {. Try explicitly setting the syntax to plain old JSON, see if that helps?

DoomyTheFroomy commented 8 years ago

@denizdogan yes this will help, but does not work for my case. Because it is a configure file for another program, which I have to configure in exactly this way. This why I was hoping that excludes will do what it should and exclude all json files in my case. 😏 But thanks for the hint, I could solve my problem, or better say find a workaround. I have switched the file syntax from JSON (Javascript Next), which contains Javascript, to clean JSON. This works.

denizdogan commented 8 years ago

@DoomyTheFroomy Great, I am currently writing a fix for this, hopefully it will be included

DoomyTheFroomy commented 8 years ago

@denizdogan 👍

bcomnes commented 4 years ago

Use the standard ignore block in package.json