JSLint error: "Expected a newline at EOF", conflict with Beautify plugin

991 views Asked by At

I have a problem while building the sources using Grunt, with JSLint task for error check:

L177: Expected a newline at the end of the file. Warning: Formatting check failed. Use --force to continue. Aborted due to warnings.

The problem is obvious, but I use also the Beautify plugin for Brackets from: https://github.com/drewhamlett/brackets-beautify which by default removes all the new lines from the end of file.

My configuration for JSLint task in Gruntfile.js:

jslint: {
            server: {
                src: [
                    '<%= config.PATH %>/src/**/*.js',
                ],
                directives: {
                    indent: 4,
                    plusplus: true,
                    unparam: true,
                    todo: true,
                    globals: [
                        'angular'
                    ]
                },
                options: {
                    edition: 'latest', // specify an edition of jslint or use 'dir/mycustom-jslint.js' for own path
                    errorsOnly: true, // only display errors
                    failOnError: true // defaults to true
                }
            }
        }

My question is, how to change the JSLint configuration in Gruntfile.js to ignore the newline at EOF or to force the Beautify plugin to add (or simply do not remove) the new lines at the end of file?

1

There are 1 answers

3
Frank Schmitt On BEST ANSWER

According to the Brackets Beautify Documentation, it uses JS-Beautify internally. The documentation for the latter mentions these parameters:

-n, --end-with-newline
-p, --preserve-newlines

If you can force Adobe Brackets to pass parameters to the js-beautify call, I guess one of these should do the trick.

UPDATE

According to the Github repo, brackets beautify uses a settings.json internally for configuration. Adding

"end_with_newline": true

might be easier than hacking the command-line call.

2nd UPDATE

If I understand the README correctly, an extension is just a folder, so this should work:

  • find the extensions folder: menu "Help > Show Extensions Folder"
  • locate the subfolder for the Beautify plugin
  • change settings.json inside the plugin folder
  • (probably) restart Adobe Brackets