This app provides monitoring and information features for the common freifunk user and the technical stuff of a freifunk community.
Code base is taken from a TUM Practical Course project and added here to see if Freifunk Altdorf can use it.
https://www.freifunk-altdorf.de
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.7 KiB
65 lines
1.7 KiB
/** |
|
* @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 = [];
|
|
|