Fix linting, warnings, add noinspection suppression comments.

This commit is contained in:
Mikael Sand
2017-07-24 00:08:28 +03:00
parent 80b9ff9d57
commit 1a9a051ee9
21 changed files with 66 additions and 49 deletions

View File

@@ -80,6 +80,7 @@ Here's a simple example. To render output like this:
Use the following code: Use the following code:
```javascript ```javascript
import 'react';
import Svg,{ import Svg,{
Circle, Circle,
Ellipse, Ellipse,

View File

@@ -5,6 +5,7 @@ import createReactNativeComponentClass from 'react-native/Libraries/Renderer/shi
import {ImageAttributes} from '../lib/attributes'; import {ImageAttributes} from '../lib/attributes';
import {numberProp, touchableProps, responderProps} from '../lib/props'; import {numberProp, touchableProps, responderProps} from '../lib/props';
import Shape from './Shape'; import Shape from './Shape';
//noinspection JSUnresolvedVariable
import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource'; import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';
import {meetOrSliceTypes, alignEnum} from '../lib/extract/extractViewBox'; import {meetOrSliceTypes, alignEnum} from '../lib/extract/extractViewBox';
import extractProps from '../lib/extract/extractProps'; import extractProps from '../lib/extract/extractProps';

View File

@@ -16,6 +16,7 @@ export default class extends Component{
}; };
setNativeProps = (...args) => { setNativeProps = (...args) => {
//noinspection JSUnresolvedFunction
this.root.getNativeElement().setNativeProps(...args); this.root.getNativeElement().setNativeProps(...args);
}; };

View File

@@ -16,6 +16,7 @@ export default class extends Component{
}; };
setNativeProps = (...args) => { setNativeProps = (...args) => {
//noinspection JSUnresolvedFunction
this.root.getNativeElement().setNativeProps(...args); this.root.getNativeElement().setNativeProps(...args);
}; };

View File

@@ -8,6 +8,7 @@ class Shape extends Component {
_.forEach(SvgTouchableMixin, (method, key) => { _.forEach(SvgTouchableMixin, (method, key) => {
this[key] = method.bind(this); this[key] = method.bind(this);
}); });
//noinspection JSUnusedGlobalSymbols
this.state = this.touchableGetInitialState(); this.state = this.touchableGetInitialState();
} }
} }

View File

@@ -1,3 +1,4 @@
//noinspection JSUnresolvedVariable
import React, { import React, {
Component Component
} from 'react'; } from 'react';
@@ -12,6 +13,7 @@ import {
import extractViewBox from '../lib/extract/extractViewBox'; import extractViewBox from '../lib/extract/extractViewBox';
import {ViewBoxAttributes} from '../lib/attributes'; import {ViewBoxAttributes} from '../lib/attributes';
/** @namespace NativeModules.RNSVGSvgViewManager */
const RNSVGSvgViewManager = NativeModules.RNSVGSvgViewManager; const RNSVGSvgViewManager = NativeModules.RNSVGSvgViewManager;
// Svg - Root node of all Svg elements // Svg - Root node of all Svg elements
@@ -43,6 +45,7 @@ class Svg extends Component{
super(...arguments); super(...arguments);
id++; id++;
this.id = id; this.id = id;
//noinspection JSUnusedGlobalSymbols
this.onDataURLCallbacks = []; this.onDataURLCallbacks = [];
} }
measureInWindow = (...args) => { measureInWindow = (...args) => {
@@ -61,7 +64,7 @@ class Svg extends Component{
this.root.setNativeProps(...args); this.root.setNativeProps(...args);
}; };
toDataURL = (callback: Function) => { toDataURL = (callback) => {
callback && RNSVGSvgViewManager.toDataURL(findNodeHandle(this.root), callback); callback && RNSVGSvgViewManager.toDataURL(findNodeHandle(this.root), callback);
}; };

View File

@@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import createReactNativeComponentClass from 'react-native/Libraries/Renderer/shims/createReactNativeComponentClass'; import createReactNativeComponentClass from 'react-native/Libraries/Renderer/shims/createReactNativeComponentClass';
import extractText from '../lib/extract/extractText'; import extractText from '../lib/extract/extractText';
import {numberProp, pathProps, fontProps} from '../lib/props'; import {pathProps, fontProps} from '../lib/props';
import {TSpanAttibutes} from '../lib/attributes'; import {TSpanAttibutes} from '../lib/attributes';
import extractProps from '../lib/extract/extractProps'; import extractProps from '../lib/extract/extractProps';
import Shape from './Shape'; import Shape from './Shape';
@@ -18,16 +18,19 @@ export default class extends Shape {
dy: PropTypes.string, dy: PropTypes.string,
}; };
//noinspection JSUnusedGlobalSymbols
static childContextTypes = { static childContextTypes = {
isInAParentText: PropTypes.bool isInAParentText: PropTypes.bool
}; };
//noinspection JSUnusedGlobalSymbols
getChildContext() { getChildContext() {
return { return {
isInAParentText: true isInAParentText: true
}; };
} }
//noinspection JSUnusedGlobalSymbols
getContextTypes() { getContextTypes() {
return { return {
isInAParentText: PropTypes.bool isInAParentText: PropTypes.bool

View File

@@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import createReactNativeComponentClass from 'react-native/Libraries/Renderer/shims/createReactNativeComponentClass'; import createReactNativeComponentClass from 'react-native/Libraries/Renderer/shims/createReactNativeComponentClass';
import extractText from '../lib/extract/extractText'; import extractText from '../lib/extract/extractText';
import {numberProp, pathProps, fontProps} from '../lib/props'; import {pathProps, fontProps} from '../lib/props';
import {TextAttributes} from '../lib/attributes'; import {TextAttributes} from '../lib/attributes';
import extractProps from '../lib/extract/extractProps'; import extractProps from '../lib/extract/extractProps';
import Shape from './Shape'; import Shape from './Shape';
@@ -17,16 +17,19 @@ export default class extends Shape {
dy: PropTypes.string, dy: PropTypes.string,
}; };
//noinspection JSUnusedGlobalSymbols
static childContextTypes = { static childContextTypes = {
isInAParentText: PropTypes.bool isInAParentText: PropTypes.bool
}; };
//noinspection JSUnusedGlobalSymbols
getChildContext() { getChildContext() {
return { return {
isInAParentText: true isInAParentText: true
}; };
} }
//noinspection JSUnusedGlobalSymbols
getContextTypes() { getContextTypes() {
return { return {
isInAParentText: PropTypes.bool isInAParentText: PropTypes.bool

View File

@@ -4,7 +4,7 @@ import createReactNativeComponentClass from 'react-native/Libraries/Renderer/shi
import {TextPathAttributes} from '../lib/attributes'; import {TextPathAttributes} from '../lib/attributes';
import extractText from '../lib/extract/extractText'; import extractText from '../lib/extract/extractText';
import Shape from './Shape'; import Shape from './Shape';
import {pathProps, fontProps, numberProp} from '../lib/props'; import {pathProps, fontProps} from '../lib/props';
import extractProps from '../lib/extract/extractProps'; import extractProps from '../lib/extract/extractProps';
import TSpan from './TSpan'; import TSpan from './TSpan';

View File

@@ -42,4 +42,5 @@ export {
ClipPath ClipPath
}; };
//noinspection JSUnusedGlobalSymbols
export default Svg; export default Svg;

View File

@@ -79,13 +79,13 @@ export default class Matrix2D {
* @return {Matrix2D} This instance. Useful for chaining method calls. * @return {Matrix2D} This instance. Useful for chaining method calls.
*/ */
setTransform = function(a, b, c, d, tx, ty) { setTransform = function(a, b, c, d, tx, ty) {
/*eslint eqeqeq:0*/ this.a = a === null || a === undefined ? 1 : a;
this.a = a == null ? 1 : a;
this.b = b || 0; this.b = b || 0;
this.c = c || 0; this.c = c || 0;
this.d = d == null ? 1 : d; this.d = d === null || d === undefined ? 1 : d;
this.tx = tx || 0; this.tx = tx || 0;
this.ty = ty || 0; this.ty = ty || 0;
//noinspection JSValidateTypes
return this; return this;
}; };
@@ -97,6 +97,7 @@ export default class Matrix2D {
reset = function() { reset = function() {
this.a = this.d = 1; this.a = this.d = 1;
this.b = this.c = this.tx = this.ty = 0; this.b = this.c = this.tx = this.ty = 0;
//noinspection JSValidateTypes
return this; return this;
}; };
@@ -109,6 +110,7 @@ export default class Matrix2D {
return [this.a, this.b, this.c, this.d, this.tx, this.ty]; return [this.a, this.b, this.c, this.d, this.tx, this.ty];
}; };
//noinspection JSUnusedGlobalSymbols
/** /**
* Copies all properties from the specified matrix to this matrix. * Copies all properties from the specified matrix to this matrix.
* @method copy * @method copy
@@ -116,9 +118,11 @@ export default class Matrix2D {
* @return {Matrix2D} This matrix. Useful for chaining method calls. * @return {Matrix2D} This matrix. Useful for chaining method calls.
*/ */
copy = function(matrix) { copy = function(matrix) {
//noinspection JSUnresolvedVariable
return this.setTransform(matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty); return this.setTransform(matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty);
}; };
//noinspection JSUnusedGlobalSymbols
/** /**
* Clones current instance and returning a new matrix. * Clones current instance and returning a new matrix.
* @method clone * @method clone
@@ -142,9 +146,9 @@ export default class Matrix2D {
* @return {Matrix2D} This matrix. Useful for chaining method calls. * @return {Matrix2D} This matrix. Useful for chaining method calls.
**/ **/
prepend = function(a, b, c, d, tx, ty) { prepend = function(a, b, c, d, tx, ty) {
var a1 = this.a; const a1 = this.a;
var c1 = this.c; const c1 = this.c;
var tx1 = this.tx; const tx1 = this.tx;
this.a = a * a1 + c * this.b; this.a = a * a1 + c * this.b;
this.b = b * a1 + d * this.b; this.b = b * a1 + d * this.b;
@@ -152,6 +156,7 @@ export default class Matrix2D {
this.d = b * c1 + d * this.d; this.d = b * c1 + d * this.d;
this.tx = a * tx1 + c * this.ty + tx; this.tx = a * tx1 + c * this.ty + tx;
this.ty = b * tx1 + d * this.ty + ty; this.ty = b * tx1 + d * this.ty + ty;
//noinspection JSValidateTypes
return this; return this;
}; };
@@ -168,10 +173,10 @@ export default class Matrix2D {
* @return {Matrix2D} This matrix. Useful for chaining method calls. * @return {Matrix2D} This matrix. Useful for chaining method calls.
**/ **/
append = function(a, b, c, d, tx, ty) { append = function(a, b, c, d, tx, ty) {
var a1 = this.a; const a1 = this.a;
var b1 = this.b; const b1 = this.b;
var c1 = this.c; const c1 = this.c;
var d1 = this.d; const d1 = this.d;
if (a !== 1 || b !== 0 || c !== 0 || d !== 1) { if (a !== 1 || b !== 0 || c !== 0 || d !== 1) {
this.a = a1 * a + c1 * b; this.a = a1 * a + c1 * b;
this.b = b1 * a + d1 * b; this.b = b1 * a + d1 * b;
@@ -180,6 +185,7 @@ export default class Matrix2D {
} }
this.tx = a1 * tx + c1 * ty + this.tx; this.tx = a1 * tx + c1 * ty + this.tx;
this.ty = b1 * tx + d1 * ty + this.ty; this.ty = b1 * tx + d1 * ty + this.ty;
//noinspection JSValidateTypes
return this; return this;
}; };
@@ -202,10 +208,11 @@ export default class Matrix2D {
* @return {Matrix2D} This matrix. Useful for chaining method calls. * @return {Matrix2D} This matrix. Useful for chaining method calls.
**/ **/
appendTransform = function(x, y, scaleX, scaleY, rotation, skewX, skewY, regX, regY) { appendTransform = function(x, y, scaleX, scaleY, rotation, skewX, skewY, regX, regY) {
let cos, sin;
if (rotation % 360) { if (rotation % 360) {
var r = rotation * DEG_TO_RAD; const r = rotation * DEG_TO_RAD;
var cos = Math.cos(r); cos = Math.cos(r);
var sin = Math.sin(r); sin = Math.sin(r);
} else { } else {
cos = 1; cos = 1;
sin = 0; sin = 0;
@@ -226,9 +233,11 @@ export default class Matrix2D {
this.tx -= regX * this.a + regY * this.c; this.tx -= regX * this.a + regY * this.c;
this.ty -= regX * this.b + regY * this.d; this.ty -= regX * this.b + regY * this.d;
} }
//noinspection JSValidateTypes
return this; return this;
}; };
//noinspection JSUnusedGlobalSymbols
/** /**
* Generates matrix properties from the specified display object transform properties, and prepends them to this matrix. * Generates matrix properties from the specified display object transform properties, and prepends them to this matrix.
* For example, you could calculate the combined transformation for a child object using: * For example, you could calculate the combined transformation for a child object using:
@@ -255,10 +264,11 @@ export default class Matrix2D {
* @return {Matrix2D} This matrix. Useful for chaining method calls. * @return {Matrix2D} This matrix. Useful for chaining method calls.
**/ **/
prependTransform = function(x, y, scaleX, scaleY, rotation, skewX, skewY, regX, regY) { prependTransform = function(x, y, scaleX, scaleY, rotation, skewX, skewY, regX, regY) {
let cos, sin;
if (rotation % 360) { if (rotation % 360) {
var r = rotation * DEG_TO_RAD; const r = rotation * DEG_TO_RAD;
var cos = Math.cos(r); cos = Math.cos(r);
var sin = Math.sin(r); sin = Math.sin(r);
} else { } else {
cos = 1; cos = 1;
sin = 0; sin = 0;
@@ -277,6 +287,7 @@ export default class Matrix2D {
} else { } else {
this.prepend(cos * scaleX, sin * scaleX, -sin * scaleY, cos * scaleY, x, y); this.prepend(cos * scaleX, sin * scaleX, -sin * scaleY, cos * scaleY, x, y);
} }
//noinspection JSValidateTypes
return this; return this;
}; };
} }

View File

@@ -1,6 +1,7 @@
import Touchable from 'react-native/Libraries/Components/Touchable/Touchable'; import Touchable from 'react-native/Libraries/Components/Touchable/Touchable';
const PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30}; const PRESS_RETENTION_OFFSET = {top: 20, left: 20, right: 20, bottom: 30};
//noinspection JSUnusedGlobalSymbols
export default { export default {
...Touchable.Mixin, ...Touchable.Mixin,

View File

@@ -1,13 +1,12 @@
function arrayDiffer(a, b) { function arrayDiffer(a, b) {
/*eslint eqeqeq:0*/ if (!a || !b) {
if (a == null || b == null) {
return true; return true;
} }
if (a.length !== b.length) { if (a.length !== b.length) {
return true; return true;
} }
for (var i = 0; i < a.length; i++) { for (let i = 0; i < a.length; i++) {
if (a[i] !== b[i]) { if (a[i] !== b[i]) {
return true; return true;
} }

View File

@@ -2,8 +2,7 @@ import Color from 'color';
import patternReg from './patternReg'; import patternReg from './patternReg';
export default function (colorOrBrush) { export default function (colorOrBrush) {
/*eslint eqeqeq:0*/ if (colorOrBrush === 'none' || !colorOrBrush) {
if (colorOrBrush === 'none' || colorOrBrush == null) {
return null; return null;
} }

View File

@@ -18,8 +18,7 @@ export default function(props, styleProperties) {
return { return {
// default fill is black // default fill is black
/*eslint eqeqeq:0*/ fill: extractBrush(props.fill || '#000'),
fill: extractBrush(props.fill == null ? '#000' : props.fill),
fillOpacity: extractOpacity(props.fillOpacity), fillOpacity: extractOpacity(props.fillOpacity),
fillRule: fillRules[props.fillRule] === 0 ? 0 : 1 fillRule: fillRules[props.fillRule] === 0 ? 0 : 1
}; };

View File

@@ -21,6 +21,7 @@ export default function(props) {
let offset = percentToFloat(child.props.offset); let offset = percentToFloat(child.props.offset);
// add stop // add stop
//noinspection JSUnresolvedFunction
stops[offset] = Color(child.props.stopColor).alpha(extractOpacity(child.props.stopOpacity)); stops[offset] = Color(child.props.stopColor).alpha(extractOpacity(child.props.stopOpacity));
} }
} else { } else {

View File

@@ -30,7 +30,7 @@ export default function(props, ref) {
let transform = props.transform; let transform = props.transform;
if (transform) { if (transform) {
if (typeof transform === 'string') { if (typeof transform === 'string') {
var transformParsed = tp.parse(transform); const transformParsed = tp.parse(transform);
if (transformParsed.matrix) { if (transformParsed.matrix) {
// TODO: Extract scaling values for coordinate system // TODO: Extract scaling values for coordinate system
// Especially scaleY for calculating scaling of fontSize // Especially scaleY for calculating scaling of fontSize

View File

@@ -44,7 +44,7 @@ export default function(props, styleProperties) {
strokeLinecap: caps[props.strokeLinecap] || 0, strokeLinecap: caps[props.strokeLinecap] || 0,
strokeLinejoin: joins[props.strokeLinejoin] || 0, strokeLinejoin: joins[props.strokeLinejoin] || 0,
strokeDasharray: strokeDasharray || null, strokeDasharray: strokeDasharray || null,
strokeWidth: strokeWidth || "1", strokeWidth: strokeWidth || '1',
strokeDashoffset: strokeDasharray ? (+props.strokeDashoffset || 0) : null, strokeDashoffset: strokeDasharray ? (+props.strokeDashoffset || 0) : null,
strokeMiterlimit: props.strokeMiterlimit || 4 strokeMiterlimit: props.strokeMiterlimit || 4
}; };

View File

@@ -1,4 +1,5 @@
import _ from 'lodash'; import _ from 'lodash';
//noinspection JSUnresolvedVariable
import React, {Children} from 'react'; import React, {Children} from 'react';
import TSpan from '../../elements/TSpan'; import TSpan from '../../elements/TSpan';
@@ -28,7 +29,7 @@ function parseFontString(font) {
return null; return null;
} }
const fontFamily = extractSingleFontFamily(match[3]); const fontFamily = extractSingleFontFamily(match[3]);
const fontSize = match[2] || "12"; const fontSize = match[2] || '12';
const isBold = /bold/.exec(match[1]); const isBold = /bold/.exec(match[1]);
const isItalic = /italic/.exec(match[1]); const isItalic = /italic/.exec(match[1]);
const fontWeight = isBold ? 'bold' : 'normal'; const fontWeight = isBold ? 'bold' : 'normal';

View File

@@ -15,11 +15,11 @@ function transformToMatrix(props, transform) {
class TransformParser { class TransformParser {
constructor() { constructor() {
var floating = '(\\-?[\\d\\.e]+)'; const floating = '(\\-?[\\d\\.e]+)';
var commaSpace = '\\,?\\s*'; const commaSpace = '\\,?\\s*';
this.regex = { this.regex = {
split: /[\s*(\s*|\s*)\s*|\s*,\s*]/, split: /[\s*()|,]/,
matrix: new RegExp( matrix: new RegExp(
'^matrix\\(' + '^matrix\\(' +
floating + commaSpace + floating + commaSpace +
@@ -33,7 +33,7 @@ class TransformParser {
parse(transform) { parse(transform) {
if (transform) { if (transform) {
var retval = {}; const retval = {};
let transLst = _.filter( let transLst = _.filter(
transform.split(this.regex.split), transform.split(this.regex.split),
(ele) => { (ele) => {
@@ -50,11 +50,11 @@ class TransformParser {
break; break;
case 'translate': case 'translate':
retval.translateX = transLst[i + 1]; retval.translateX = transLst[i + 1];
retval.translateY = (3 === transLst.length) ? transLst[i + 2] : 0; retval.translateY = (transLst.length === 3) ? transLst[i + 2] : 0;
break; break;
case 'scale': case 'scale':
retval.scaleX = transLst[i + 1]; retval.scaleX = transLst[i + 1];
retval.scaleY = (3 === transLst.length) ? transLst[i + 2] : retval.scaleX; retval.scaleY = (transLst.length === 3) ? transLst[i + 2] : retval.scaleX;
break; break;
case 'rotate': case 'rotate':
retval.rotation = transLst[i + 1]; retval.rotation = transLst[i + 1];
@@ -72,17 +72,6 @@ class TransformParser {
return retval; return retval;
} }
} }
parseMatrix(transform) {
var matrix = this.regex.matrix.exec(transform);
if (matrix) {
matrix.shift();
for (var i = matrix.length - 1; i >= 0; i--) {
matrix[i] = parseFloat(matrix[i]);
}
}
return matrix;
}
} }
export const tp = new TransformParser(); export const tp = new TransformParser();
@@ -91,7 +80,7 @@ export const tp = new TransformParser();
function appendTransform(transform) { function appendTransform(transform) {
if (transform) { if (transform) {
if (typeof transform === 'string') { if (typeof transform === 'string') {
var transformParsed = tp.parse(transform); const transformParsed = tp.parse(transform);
if (transformParsed.matrix) { if (transformParsed.matrix) {
pooledMatrix.append(...transformParsed.matrix); pooledMatrix.append(...transformParsed.matrix);
} }

View File

@@ -34,7 +34,9 @@
"babel-eslint": "^6.1.2", "babel-eslint": "^6.1.2",
"eslint": "^2.13.1", "eslint": "^2.13.1",
"eslint-plugin-react": "^4.3.0", "eslint-plugin-react": "^4.3.0",
"react-native": "^0.46.0" "prop-types": "^15.5.10",
"react": "^16.0.0-alpha.12",
"react-native": ">=0.46.0"
}, },
"nativePackage": true "nativePackage": true
} }