Node JS avoids the painstaking addition of "strict use" to all my files

So, I want to enable strict mode for my project, but I have many files, and adding "use strict";all of them to the beginning would be a pain. I found the --use_strictCLI option for node, which is awesome, but allows it for every single file inside my project directory, including all third-party modules and their modules, and I really don't want to fix all the files, just mine.

So my question is: is there a way to automate adding "use strict" only to my files?

+4
source share
3 answers

script, "use strict"\n .

:

var fs = require("fs"),
   files = fs.readDirSync('./'),
   i;

for (i = 0; i < files.length; i += 1) {
  var fileContent = fs.readFileSync(files[i]).toString();
  fileContent = "\"use strict\"\n" + fileContent;
  fs.appendFileSync(files[i], fileContent);
}

, file[i] , , .

fooobar.com/questions/247559/... fooobar.com/questions/208181/....

+4

use-strict-cli - Node.js / "use strict" , .

:

https://github.com/philidem/use-strict-cli

"use strict ":

use-strict./src

"use strict":

use-strict./src --remove

+2

jshint , , .

.jshintrc - :

{
  "immed": true,
  "latedef": true,
  "newcap": true,
  "nonew": true,
  "trailing": true,
  "multistr": true,
  "devel": true
}

, strict: true . , jshint true :)

jshint git pre-commit (, SublimeLinter Sublime 3)

+1
source

Source: https://habr.com/ru/post/1532794/


All Articles