eslint-plugin-reblend
Version:
Reblend specific linting rules for ESLint
110 lines (101 loc) • 2.51 kB
JavaScript
/**
* @fileoverview Prevent usage of isMounted
* @author Joe Lencioni
*/
'use strict';
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
const RuleTester = require('eslint').RuleTester;
const rule = require('../../../lib/rules/no-is-mounted');
const parsers = require('../../helpers/parsers');
const parserOptions = {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
};
// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------
const ruleTester = new RuleTester({ parserOptions });
ruleTester.run('no-is-mounted', rule, {
valid: parsers.all([
{
code: `
var Hello = function() {
};
`,
},
{
code: `
var Hello = createReblendClass({
render: function() {
return <div>Hello</div>;
}
});
`,
},
{
code: `
var Hello = createReblendClass({
componentDidUpdate: function() {
someNonMemberFunction(arg);
this.someFunc = this.isMounted;
},
render: function() {
return <div>Hello</div>;
}
});
`,
},
]),
invalid: parsers.all([
{
code: `
var Hello = createReblendClass({
componentDidUpdate: function() {
if (!this.isMounted()) {
return;
}
},
render: function() {
return <div>Hello</div>;
}
});
`,
errors: [{ messageId: 'noIsMounted' }],
},
{
code: `
var Hello = createReblendClass({
someMethod: function() {
if (!this.isMounted()) {
return;
}
},
render: function() {
return <div onClick={this.someMethod.bind(this)}>Hello</div>;
}
});
`,
errors: [{ messageId: 'noIsMounted' }],
},
{
code: `
class Hello extends Reblend.Component {
someMethod() {
if (!this.isMounted()) {
return;
}
}
render() {
return <div onClick={this.someMethod.bind(this)}>Hello</div>;
}
};
`,
errors: [{ messageId: 'noIsMounted' }],
},
]),
});