Skip to content

Latest commit

 

History

History
136 lines (113 loc) · 2.84 KB

msg-doc.md

File metadata and controls

136 lines (113 loc) · 2.84 KB

msg-doc

Ensures message keys are documented when they are constructed.

📋 This rule is enabled in plugin:mediawiki/common.

Rule details

❌ Examples of incorrect code:

message = mw.msg( 'foo-' + bar );
message = mw.msg( cond ? 'baz' : 'foo-' + bar );
message = new mw.Message( cond ? 'baz' : 'foo-' + bar );
message = this.$i18n( 'foo-' + bar );

// This can produce:
// * foo-bar-baz
message = mw.msg( 'foo-' + bar );

// This can produce:
// * foo-bar-baz
// * foo-bar-baz
message = mw.msg( 'foo-' + bar );

// This constructs foo-baz or foo-quux
message = mw.msg( 'foo-' + bar );

/**
 The following messages are used here:
 * foo-baz
 * foo-quux
 */
display( mw.msg( 'foo-' + bar ), baz );

function foo() {
    const first = mw.msg( 'foo-' + baz ),
        // This can produce:
        // * bar-x
        // * bar-y
        second = mw.msg( 'bar-' + baz );
}

function foo() {
    const
        // This can produce:
        // * foo-x
        // * foo-y
        first = mw.msg( 'foo-' + baz ),
        second = mw.msg( 'bar-' + baz );
}

function foo() {
    // This can produce:
    // * foo-x
    // * foo-y
    const first = mw.msg( 'foo-' + baz ),
        second = mw.msg( 'bar-' + baz );
}

function foo() {
    let first = mw.msg( 'foo-' + baz ), second;
    bar.quux();
    // This can produce:
    // * bar-x
    // * bar-y
    second = mw.msg( 'bar-' + baz );
}

✔️ Examples of correct code:

// The following messages are used here:
// * foo-baz
// * foo-quux
display( mw.msg( 'foo-' + bar ), baz );

// The following messages are used here:
// * foo-baz
// * foo-quux
// * foo-whee
message = mw.msg( 'foo-' + bar );

$foo
    // The following messages are used here:
    // * foo-baz
    // * foo-quux
    .text( mw.msg( 'foo-' + bar ) );

// The following messages are used here:
// * foo-baz
// * foo-quux
this.$i18n( 'foo-' + bar );

function foo() {
    const
        // This can produce:
        // * foo-x
        // * foo-y
        first = mw.msg( 'foo-' + baz ),
        // This can produce:
        // * bar-x
        // * bar-y
        second = mw.msg( 'bar-' + baz );
}

function foo() {
    // This can produce:
    // * foo-x
    // * foo-y
    const first = mw.msg( 'foo-' + baz ),
        // This can produce:
        // * bar-x
        // * bar-y
        second = mw.msg( 'bar-' + baz );
}

// This can produce:
// * foo-x
// * foo-y
new mw.Message( 'foo-' + baz );

message = mw.msg( test ? 'foo' : 'bar' );
message = mw.msg( test ? ( test2 ? 'foo' : 'bar' ) : ( test2 ? 'baz' : 'quux' ) );
message = mw.msg( 'foo-bar' );
message = mw.message( 'foo-bar' ).plain();
message = OO.ui.deferMsg( 'foo-bar' );
message = ve.msg( 'foo-bar' );
message = mw.msg();

Resources