Permalink
Browse files

Framework: Upgrade ESLint no-console to error

  • Loading branch information...
1 parent cd2d53d commit 7704fb11e46345b23ab26c1db136d397858d60fb @aduth aduth committed Oct 31, 2016
View
@@ -26,7 +26,6 @@ module.exports = {
'keyword-spacing': 1,
'max-len': [ 1, { code: 140 } ],
'new-cap': [ 1, { capIsNew: false, newIsCap: true } ],
- 'no-console': 1,
'no-else-return': 1,
'no-extra-semi': 1,
'no-lonely-if': 1,
@@ -2,7 +2,6 @@
* External dependencies
*/
var expect = require( 'chai' ).expect,
- sinon = require( 'sinon' ),
useMockery = require( 'test/helpers/use-mockery' );
describe( 'Count', function() {
@@ -78,10 +77,4 @@ describe( 'Count', function() {
expect( result.props.children ).to.equal( '3' );
} );
-
- it( 'should warn when passing something that is not a number', sinon.test( function() {
- this.stub( console, 'error' );
- renderer.render( <Count count={ "17" } /> );
- expect( console.error ).to.have.been.called;
- } ) );
} );
@@ -1,3 +1,14 @@
+/* eslint-disable no-console */
+
+/**
+ * External dependencies
+ */
+import debug from 'debug';
+
+/**
+ * Module variables
+ */
+const log = debug( 'calypso:docs-example:util' );
const getComponentName = docsExample => {
if ( ! docsExample ) {
@@ -17,7 +28,7 @@ const getComponentName = docsExample => {
const slugToCamelCase = name => {
if ( ! name ) {
- console.warn( 'name is not defined' );
+ log( 'name is not defined' );
return console.trace();
}
@@ -28,7 +39,7 @@ const slugToCamelCase = name => {
const camelCaseToSlug = name => {
if ( ! name ) {
- console.warn( 'name is not defined' );
+ log( 'name is not defined' );
return console.trace();
}
@@ -3,6 +3,7 @@
*/
var React = require( 'react' ),
isFunction = require( 'lodash/isFunction' );
+import debug from 'debug';
/**
* Internal dependencies
@@ -12,15 +13,25 @@ var DocService = require( './service' ),
Main = require( 'components/main' ),
SearchCard = require( 'components/search-card' );
+/**
+ * Constants
+ */
+
var DEFAULT_FILES = [
- 'docs/guide/index.md',
- 'README.md',
- '.github/CONTRIBUTING.md',
- 'docs/coding-guidelines.md',
- 'docs/coding-guidelines/javascript.md',
- 'docs/coding-guidelines/css.md',
- 'docs/coding-guidelines/html.md'
- ];
+ 'docs/guide/index.md',
+ 'README.md',
+ '.github/CONTRIBUTING.md',
+ 'docs/coding-guidelines.md',
+ 'docs/coding-guidelines/javascript.md',
+ 'docs/coding-guidelines/css.md',
+ 'docs/coding-guidelines/html.md'
+];
+
+/**
+ * Module variables
+ */
+
+const log = debug( 'calypso:devdocs' );
module.exports = React.createClass( {
displayName: 'Devdocs',
@@ -93,7 +104,7 @@ module.exports = React.createClass( {
}
DocService.search( term, function( err, results ) {
if ( err ) {
- console.log( err );
+ log( 'search error: %o', err );
}
this.setState( {
@@ -6,13 +6,19 @@ var ReactDom = require( 'react-dom' ),
assign = require( 'lodash/assign' ),
url = require( 'url' ),
qs = require( 'querystring' );
+import debug from 'debug';
/**
* Internal dependencies
*/
var analytics = require( 'lib/analytics' ),
EmptyContent = require( 'components/empty-content' );
+/**
+ * Module variables
+ */
+const log = debug( 'calypso:layout' );
+
var LoadingError = React.createClass( {
statics: {
@@ -34,7 +40,7 @@ var LoadingError = React.createClass( {
},
show: function( chunkName ) {
- console.error( 'Chunk %s could not be loaded', chunkName );
+ log( 'Chunk %s could not be loaded', chunkName );
analytics.mc.bumpStat( 'calypso_chunk_error', chunkName );
ReactDom.render(
React.createElement( LoadingError, {} ),
@@ -1,8 +1,28 @@
+/**
+ * External dependencies
+ */
import TraceKit from 'tracekit';
+import debug from 'debug';
-// Interval for error reports so we don't flood te endpoint. More frequent reports get throttled.
+/**
+ * Module variables
+ */
+
+/**
+ * Interval for error reports so we don't flood te endpoint. More frequent
+ * reports get throttled.
+ *
+ * @type {Number}
+ */
const REPORT_INTERVAL = 60000;
+/**
+ * Debug logger
+ *
+ * @type {Function}
+ */
+const log = debug( 'calypso:error-logger' );
+
export default class ErrorLogger {
constructor() {
this.diagnosticData = {
@@ -79,7 +99,7 @@ export default class ErrorLogger {
this.saveDiagnosticData( diagnosticReducer() );
} catch ( e ) {
this.saveDiagnosticData( { diagnosticError: e.message } );
- console.warn( 'diagnostic', this.diagnosticData );
+ log( 'diagnostic: %o', this.diagnosticData );
}
} );
@@ -1,3 +1,5 @@
+/* eslint-disable no-console */
+
/**
* External dependencies
*/
@@ -9,28 +11,26 @@ import sinon from 'sinon';
* Internal dependencies
*/
import createSelector from '../';
+import { useSandbox } from 'test/helpers/use-sinon';
describe( 'index', () => {
let selector, getSitePosts;
- before( () => {
- selector = sinon.spy( ( state, siteId ) => {
+ useSandbox( ( sandbox ) => {
+ sandbox.stub( console, 'warn' );
+ selector = sandbox.spy( ( state, siteId ) => {
return filter( state.posts, { site_ID: siteId } );
} );
+ } );
+
+ before( () => {
getSitePosts = createSelector( selector, ( state ) => state.posts );
- sinon.stub( console, 'warn' );
} );
beforeEach( () => {
- console.warn.reset();
- selector.reset();
getSitePosts.memoizedSelector.cache.clear();
} );
- after( () => {
- console.warn.restore();
- } );
-
it( 'should expose its memoized function', () => {
expect( getSitePosts.memoizedSelector ).to.be.a( 'function' );
} );
@@ -1,3 +1,5 @@
+/* eslint-disable no-console */
+
/**
* External dependencies
*/
@@ -3,12 +3,18 @@
*/
import localforage from 'localforage';
import reduce from 'lodash/reduce';
+import debug from 'debug';
/**
* Internal dependencies
*/
import localforageBypass from './localforage-bypass';
+/**
+ * Module variables
+ */
+const log = debug( 'calypso:localforage' );
+
const config = {
name: 'calypso',
storeName: 'calypso_store',
@@ -29,7 +35,7 @@ const localForagePromise = localforage.defineDriver( localforageBypass )
_ready = true;
return localforage;
} )
- .catch( ( error ) => console.error( 'Configuring localforage: %s', error ) );
+ .catch( ( error ) => log( 'Configuring localforage: %s', error ) );
// Wraps a function to run after waiting until a promise has resolved.
// The promise should contain the original object for context.
@@ -58,7 +64,7 @@ const localForageProxy = reduce(
localForageProxy.bypass = () => {
if ( _ready ) {
- console.error( 'Cannot bypass localforage after initialization' );
+ log( 'Cannot bypass localforage after initialization' );
} else {
config.driver = [ localforageBypass._driver ];
}
@@ -60,20 +60,17 @@ var pluginsInstallCalls = 0,
},
siteMock = {
- plugin: function( pluginId ) {
- console.log( 'Create %s plugin', pluginId );
+ plugin: function() {
return pluginMock;
},
- wpcomPlugin: function( pluginId ) {
- console.log( 'Create %s wpcom plugin', pluginId );
+ wpcomPlugin: function() {
return wpcomPluginMock;
}
},
mock = {
- site: function( siteId ) {
- console.log( 'Create %s site', siteId );
+ site: function() {
return siteMock;
},
@@ -1,6 +1,9 @@
+/* eslint-disable no-console */
+
/**
- * This file is served as-is as /service-worker.js
- **/
+ * WARNING: DO NOT USE ES2015+ OR COMMONJS. This file is served as-is and isn't
+ * transpiled by Babel or bundled by Webpack.
+ */
/* eslint-disable */
'use strict';
@@ -1,4 +1,5 @@
/** @ssr-ready **/
+/* eslint-disable no-console */
/**
* Internal Dependencies
@@ -1,3 +1,8 @@
+/* eslint-disable no-console */
+
+/**
+ * External dependencies
+ */
import partial from 'lodash/partial';
import isFunction from 'lodash/isFunction';
@@ -80,11 +80,6 @@ describe( 'utils', () => {
const isListsEqual = actualDatesList.equals( sortedDatesList );
- if ( ! isListsEqual ) {
- // hint what are the nodes involved
- console.error( 'Bad child nodes', childNodesList );
- }
-
expect( isListsEqual ).to.be.true;
if ( isListsEqual ) {
@@ -117,7 +117,6 @@ describe( 'reducer', () => {
const state = geo( original, { type: DESERIALIZE } );
expect( state ).to.be.null;
- expect( console.warn ).to.have.been.called; // eslint-disable-line no-console
} );
} );
} );
@@ -224,7 +224,6 @@ describe( 'reducer', () => {
const state = items( original, { type: DESERIALIZE } );
expect( state ).to.eql( {} );
- expect( console.warn ).to.have.been.calledTwice; // eslint-disable-line no-console
} );
} );
} );
@@ -215,7 +215,6 @@ describe( 'reducer', () => {
} ), { type: DESERIALIZE } );
expect( state ).to.eql( {} );
- expect( console.warn ).to.have.been.calledOnce;
} );
} );
} );
@@ -3,11 +3,11 @@
*/
import { expect } from 'chai';
import deepFreeze from 'deep-freeze';
-import sinon from 'sinon';
/**
* Internal dependencies
*/
+import { useSandbox } from 'test/helpers/use-sinon';
import {
POST_DELETE,
POST_DELETE_SUCCESS,
@@ -37,12 +37,8 @@ import reducer, {
import PostQueryManager from 'lib/query-manager/post';
describe( 'reducer', () => {
- before( () => {
- sinon.stub( console, 'warn' );
- } );
-
- after( () => {
- console.warn.restore();
+ useSandbox( ( sandbox ) => {
+ sandbox.stub( console, 'warn' );
} );
it( 'should include expected keys in return value', () => {
Oops, something went wrong.

0 comments on commit 7704fb1

Please sign in to comment.