The usual task naming convention

Is there any convention for naming custom grunt tasks containing more than one word? For example: grunt-json-schema grunt plugin has json_schema task . One name includes a dash ( - ), the other includes underscores ( _ ).

Obviously, the dotted name cannot be used as the key of a JavaScript object:

 grunt.initConfig({ json-schema: { // WON'T work 

they must be enclosed in quotation marks:

 grunt.initConfig({ 'json-schema': { // will work 

I checked all the official plugins ( grunt-contrib-* ), but they all consist of only one word. The motivation for this is simple: I just want to follow the conventions.

+7
javascript plugins gruntjs
source share
2 answers

I think the general convention is to use camelCase for multi-word tasks.

0
source share

Short answer: The names of plugins / custom tasks should not correlate with the specific name of the configuration object.

The grunt.js api allows access to the configuration object using the grunt.config method. Tasks and plugins have access to the entire object, and not just to the object corresponding to the name.

For example, I could create a task called foo that accesses the configuration from bar :

 grunt.initConfig({ bar: { baz: true } }); grunt.registerTask('foo', 'example custom task', function () { var config = grunt.config('bar'); grunt.log.ok(config); }); 

Best Practice: Plugin developers should name a key for their configuration object, similar to the plugin name itself. This helps mitigate conflicts with other plugins that may link to similar ones.

 grunt.initConfig({ foo: { baz: true } }); grunt.registerTask('foo', 'example custom task', function () { var config = grunt.config('foo'); grunt.log.ok(config); }); 
-one
source share

All Articles