Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grunt-banana-checker

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-banana-checker - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

History.md

16

Gruntfile.js

@@ -9,11 +9,11 @@ /*!

grunt.loadNpmTasks( 'grunt-contrib-watch' );
grunt.loadNpmTasks( 'grunt-jscs-checker' );
grunt.loadNpmTasks( 'grunt-jscs' );
grunt.loadTasks( './tasks/' );
grunt.initConfig( {
pkg: grunt.file.readJSON( 'package.json' ),
jshint: {
options: JSON.parse( grunt.file.read( '.jshintrc' )
.replace( /\/\*(?:(?!\*\/)[\s\S])*\*\//g, '' ).replace( /\/\/[^\n\r]*/g, '' ) ),
all: ['*.js', '{tasks,test}/**/*.js']
options: {
jshintrc: true
},
all: [ '*.js', '{tasks,test}/**/*.js' ]
},

@@ -41,9 +41,9 @@ jscs: {

watch: {
files: ['<%= jshint.all %>', '.{jshintrc,jshintignore}'],
tasks: ['test']
files: [ '<%= jshint.all %>', '.{jshintrc,jshintignore}' ],
tasks: [ 'test' ]
}
} );
grunt.registerTask( 'test', ['jshint', 'jscs', 'banana'] );
grunt.registerTask( 'test', [ 'jshint', 'jscs', 'banana' ] );
grunt.registerTask( 'default', 'test' );
};
{
"name": "grunt-banana-checker",
"version": "0.1.0",
"version": "0.2.0",
"description": "A grunt checker for the \"banana\" JSON i18n system provided by MediaWiki and jquery.i18n",

@@ -28,7 +28,7 @@ "scripts": {

"devDependencies": {
"grunt": "0.4.2",
"grunt-contrib-jshint": "0.8.0",
"grunt-contrib-watch": "0.5.3",
"grunt-jscs-checker": "0.4.1"
"grunt": "0.4.5",
"grunt-contrib-jshint": "0.10.0",
"grunt-contrib-watch": "0.5.1",
"grunt-jscs": "0.7.0"
}
}

@@ -1,4 +0,86 @@

grunt-banana-checker [![Build Status](https://travis-ci.org/jdforrester/grunt-banana-checker.svg)](https://travis-ci.org/jdforrester/grunt-banana-checker)
[![NPM version](https://badge.fury.io/js/grunt-banana-checker.svg)](http://badge.fury.io/js/grunt-banana-checker) [![Build Status](https://travis-ci.org/jdforrester/grunt-banana-checker.svg?branch=master)](https://travis-ci.org/jdforrester/grunt-banana-checker)
grunt-banana-checker
====================
A grunt checker for the "banana" JSON i18n system provided by MediaWiki and jquery.i18n.
> Task for checking JSON files for the "Banana" i18n system provided by MediaWiki and jquery.i18n.
Getting started
--------------------
If this is the first time you've used [grunt](http://gruntjs.com/), the [getting started guide](http://gruntjs.com/getting-started) will show you how to get up and running.
Once you have that installed, with a [Gruntfile](http://gruntjs.com/sample-gruntfile) set for your code, you can install the plugin with:
<pre lang=shell>
npm install grunt-banana-checker --save-dev
</pre>
In your Gruntfile, add the line:
<pre lang=js>
grunt.loadNpmTasks( 'grunt-banana-checker' );
</pre>
Running and configuring
--------------------
_Run this task with the `grunt banana` command._
This is designed to be very simple and not need configuring for the most common case.
You can specify the targets and options for the task using the normal grunt configuration – see grunt's [guide on how to configure tasks](http://gruntjs.com/configuring-tasks) in general
### Options
For edge cases you can set some path options:
### sourceFile
Type: `string`
Default value: `"en.json"`
The JSON file providing the primary messages.
### documentationFile
Type: `string`
Default value: `"qqq.json"`
The JSON file providing the documentation messages.
Example uses
--------------------
[OOjs UI](https://www.mediawiki.org/wiki/VisualEditor) uses this on [a single directory of messages](http://git.wikimedia.org/blob/oojs%2Fui.git/HEAD/Gruntfile.js):
<pre lang=js>
banana: {
all: 'i18n/'
}
</pre>
[VisualEditor](https://www.mediawiki.org/wiki/VisualEditor)'s MediaWiki extension uses this on [two directories as a single test](https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FVisualEditor.git/HEAD/Gruntfile.js):
<pre lang=js>
banana: {
all: 'modules/ve-{mw,wmf}/i18n/'
}
</pre>
[MediaWiki](https://www.mediawiki.org/wiki/MediaWiki) uses this on [two directories as different tests](https://git.wikimedia.org/blob/mediawiki%2Fcore.git/HEAD/tests%2Ffrontend%2FGruntfile.js) – one for the main software and another for the installer:
<pre lang=js>
banana: {
core: 'languages/i18n/',
installer: 'includes/installer/i18n/'
}
</pre>
Checks run
----------
* The source and documentation files both exist, and are both valid JSON.
* Both source and documentation include an "@metadata" object.
- (Note that no parsing is done of the metadata objects.)
* Each defined source message has a matching defined documentation message.
- (Note that no parsing is done of the message definitions or their documentation, including if they are simply the blank string "".)
* Each defined documentation message has a matching defined source message.
/*!
* Check for missing documentation for banana messages
* A grunt checker for the 'banana' format JSON i18n message files.
*/

@@ -19,7 +19,11 @@

sourceMessagesMetadataIndex,
message,
documentationIndex,
documentationMessages = grunt.file.readJSON( path.resolve( dir, options.documentationFile ) ),
documentationMessageKeys = Object.keys( documentationMessages ),
documentationMessageBlanks = [],
sourceMessages = grunt.file.readJSON( path.resolve( dir, options.sourceFile ) ),
sourceMessageKeys = Object.keys( sourceMessages ),
failedMessageCount = 0;
sourceIndex = 0,
count = 0;

@@ -44,16 +48,55 @@ messageCount += sourceMessageKeys.length;

sourceMessageKeys.forEach( function ( msgKey ) {
if ( documentationMessageKeys.indexOf( msgKey ) === -1 ) {
grunt.log.error( 'Message "' + msgKey + '" lacks documentation.' );
failedMessageCount++;
while (sourceMessageKeys.length > 0) {
message = sourceMessageKeys[0];
documentationIndex = documentationMessageKeys.indexOf( message );
if ( documentationIndex !== -1 ) {
if ( documentationMessages[message].trim() === '' ) {
documentationMessageBlanks.push( message );
}
documentationMessageKeys.splice( documentationIndex, 1 );
}
} );
sourceMessageKeys.splice( sourceIndex, 1 );
}
if ( failedMessageCount > 0 ) {
count = sourceMessageKeys.length;
if ( count > 0 ) {
ok = false;
grunt.log.error(
failedMessageCount + ' message' + ( failedMessageCount > 1 ? 's lack' : ' lacks' ) +
' documentation.'
count + ' message' + ( count > 1 ? 's lack' : ' lacks' ) + ' documentation.'
);
sourceMessageKeys.forEach( function ( message ) {
grunt.log.error( 'Message "' + message + '" lacks documentation.' );
} );
}
count = documentationMessageBlanks.length;
if ( count > 0 ) {
ok = false;
grunt.log.error(
count + ' documented message' + ( count > 1 ? 's are' : ' is' ) + ' blank.'
);
documentationMessageBlanks.forEach( function ( message ) {
grunt.log.error( 'Message "' + message + '" is documented with a blank string.' );
} );
}
count = documentationMessageKeys.length;
if ( count > 0 ) {
ok = false;
grunt.log.error(
count + ' documented message' + ( count > 1 ? 's are' : ' is' ) + ' undefined.'
);
documentationMessageKeys.forEach( function ( message ) {
grunt.log.error( 'Message "' + message + '" is documented but undefined.' );
} );
}
} );

@@ -60,0 +103,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc