initial commit taken from gitlab.lrz.de

This commit is contained in:
privatereese
2018-08-24 18:09:42 +02:00
parent ae54ed4c48
commit fc05486403
28494 changed files with 2159823 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
/**
* @fileoverview Detects color literals
* @author Aaron Greenwald
*/
'use strict';
const util = require('util');
const Components = require('../util/Components');
const styleSheet = require('../util/stylesheet');
const StyleSheets = styleSheet.StyleSheets;
const astHelpers = styleSheet.astHelpers;
module.exports = Components.detect((context) => {
const styleSheets = new StyleSheets();
function reportColorLiterals(colorLiterals) {
if (colorLiterals) {
colorLiterals.forEach((style) => {
if (style) {
const expression = util.inspect(style.expression);
context.report({
node: style.node,
message: 'Color literal: {{expression}}',
data: { expression },
});
}
});
}
}
return {
VariableDeclarator: (node) => {
if (astHelpers.isStyleSheetDeclaration(node)) {
const styles = astHelpers.getStyleDeclarations(node);
if (styles) {
styles.forEach((style) => {
const literals = astHelpers.collectColorLiterals(style.value, context);
styleSheets.addColorLiterals(literals);
});
}
}
},
JSXAttribute: (node) => {
if (astHelpers.isStyleAttribute(node)) {
const literals = astHelpers.collectColorLiterals(node.value, context);
styleSheets.addColorLiterals(literals);
}
},
'Program:exit': () => reportColorLiterals(styleSheets.getColorLiterals()),
};
});
module.exports.schema = [];

View File

@@ -0,0 +1,45 @@
/**
* @fileoverview Detects inline styles
* @author Aaron Greenwald
*/
'use strict';
const util = require('util');
const Components = require('../util/Components');
const styleSheet = require('../util/stylesheet');
const StyleSheets = styleSheet.StyleSheets;
const astHelpers = styleSheet.astHelpers;
module.exports = Components.detect((context) => {
const styleSheets = new StyleSheets();
function reportInlineStyles(inlineStyles) {
if (inlineStyles) {
inlineStyles.forEach((style) => {
if (style) {
const expression = util.inspect(style.expression);
context.report({
node: style.node,
message: 'Inline style: {{expression}}',
data: { expression },
});
}
});
}
}
return {
JSXAttribute: (node) => {
if (astHelpers.isStyleAttribute(node)) {
const styles = astHelpers.collectStyleObjectExpressions(node.value, context);
styleSheets.addObjectExpressions(styles);
}
},
'Program:exit': () => reportInlineStyles(styleSheets.getObjectExpressions()),
};
});
module.exports.schema = [];

View File

@@ -0,0 +1,65 @@
/**
* @fileoverview Detects unused styles
* @author Tom Hastjarjanto
*/
'use strict';
const Components = require('../util/Components');
const styleSheet = require('../util/stylesheet');
const StyleSheets = styleSheet.StyleSheets;
const astHelpers = styleSheet.astHelpers;
module.exports = Components.detect((context, components) => {
const styleSheets = new StyleSheets();
const styleReferences = new Set();
function reportUnusedStyles(unusedStyles) {
Object.keys(unusedStyles).forEach((key) => {
if ({}.hasOwnProperty.call(unusedStyles, key)) {
const styles = unusedStyles[key];
styles.forEach((node) => {
const message = [
'Unused style detected: ',
key,
'.',
node.key.name,
].join('');
context.report(node, message);
});
}
});
}
return {
MemberExpression: function (node) {
const styleRef = astHelpers.getPotentialStyleReferenceFromMemberExpression(node);
if (styleRef) {
styleReferences.add(styleRef);
}
},
VariableDeclarator: function (node) {
if (astHelpers.isStyleSheetDeclaration(node)) {
const styleSheetName = astHelpers.getStyleSheetName(node);
const styles = astHelpers.getStyleDeclarations(node);
styleSheets.add(styleSheetName, styles);
}
},
'Program:exit': function () {
const list = components.all();
if (Object.keys(list).length > 0) {
styleReferences.forEach((reference) => {
styleSheets.markAsUsed(reference);
});
reportUnusedStyles(styleSheets.getUnusedReferences());
}
},
};
});
module.exports.schema = [];

View File

@@ -0,0 +1,91 @@
/**
* @fileoverview Android and IOS components should be
* used in platform specific React Native components.
* @author Tom Hastjarjanto
*/
'use strict';
module.exports = function (context) {
let reactComponents = [];
const androidMessage = 'Android components should be placed in android files';
const iosMessage = 'IOS components should be placed in ios files';
const conflictMessage = 'IOS and Android components can\'t be mixed';
const iosPathRegex = context.options[0] && context.options[0].iosPathRegex
? new RegExp(context.options[0].iosPathRegex)
: /\.ios\.js$/;
const androidPathRegex = context.options[0] && context.options[0].androidPathRegex
? new RegExp(context.options[0].androidPathRegex)
: /\.android\.js$/;
function getName(node) {
if (node.type === 'Property') {
const key = node.key || node.argument;
return key.type === 'Identifier' ? key.name : key.value;
} else if (node.type === 'Identifier') {
return node.name;
}
}
function hasNodeWithName(nodes, name) {
return nodes.some((node) => {
const nodeName = getName(node);
return nodeName && nodeName.includes(name);
});
}
function reportErrors(components, filename) {
const containsAndroidAndIOS = (
hasNodeWithName(components, 'IOS') &&
hasNodeWithName(components, 'Android')
);
components.forEach((node) => {
const propName = getName(node);
if (propName.includes('IOS') && !filename.match(iosPathRegex)) {
context.report(node, containsAndroidAndIOS ? conflictMessage : iosMessage);
}
if (propName.includes('Android') && !filename.match(androidPathRegex)) {
context.report(node, containsAndroidAndIOS ? conflictMessage : androidMessage);
}
});
}
return {
VariableDeclarator: function (node) {
const destructuring = node.init && node.id && node.id.type === 'ObjectPattern';
const statelessDestructuring = destructuring && node.init.name === 'React';
if (destructuring && statelessDestructuring) {
reactComponents = reactComponents.concat(node.id.properties);
}
},
ImportDeclaration: function (node) {
if (node.source.value === 'react-native') {
node.specifiers.forEach((importSpecifier) => {
if (importSpecifier.type === 'ImportSpecifier') {
reactComponents = reactComponents.concat(importSpecifier.imported);
}
});
}
},
'Program:exit': function () {
const filename = context.getFilename();
reportErrors(reactComponents, filename);
},
};
};
module.exports.schema = [{
type: 'object',
properties: {
androidPathRegex: {
type: 'string',
},
iosPathRegex: {
type: 'string',
},
},
additionalProperties: false,
}];