简体   繁体   English

JavaScript代码分析-柏拉图的可维护性等级

[英]JavaScript code analysis - maintainability rating with Plato

I've been working with JavaScript for a while now and just started analyzing my code with Plato . 我已经使用JavaScript一段时间了,刚开始使用Plato分析我的代码。 I'm not sure how it calculates maintainability but the code bellow returns maintainability score of 69.3. 我不确定它如何计算可维护性,但是下面的代码返回的可维护性得分为69.3。 What am i missing? 我想念什么? Tried adding comments and it didn't change. 尝试添加评论,并且没有改变。

/*globals jQuery*/
var App = App|| {};
App.AnimateSearch = (function ($) {
    'use strict';

    var searchContainer = $('[search-container]'),
        emptySearchMessage = $('.empty-search-message');

    function animateEmptyMessage() {
        emptySearchMessage.css({
            'opacity': 0,
            'transform': 'scale(0.5)',
            '-webkit-transform': 'scale(0.5)',
            '-moz-transform': 'scale(0.5)'
        });

        emptySearchMessage.fadeIn().animate({
            'opacity': 1,
            'transform': 'scale(1)',
            '-webkit-transform': 'scale(1)',
            '-moz-transform': 'scale(1)'
        }, 300);
    }

    function animateSearch(customClass) {
        searchContainer = typeof customClass === 'undefined' ? searchContainer : $(customClass);
        searchContainer.css({ 'margin-top': '100px', 'opacity': 0 });

        setTimeout(function () {
            searchContainer.stop().animate({ 'margin-top': '0', 'opacity': 1 }, 300);
        }, 500);
    }

    return {
        animateEmptyMessage: animateEmptyMessage,
        animateSearch: animateSearch
    };
}(jQuery));

Thanks for your help/suggestions! 感谢您的帮助/建议!

Maintainability is a function of a lot of different parameters. 可维护性是许多不同参数的函数。 A maintainability around 70 is usually perfectly acceptable. 通常大约70的可维护性是完全可以接受的。 ~70+ is good, 30-70 is in a warning zone, and under 30 is usually a problem. 〜70 +是好的,30-70在警告区域,低于30通常是一个问题。 If you want to improve your score, try to move some of those css properties into css classes with animations. 如果要提高分数,请尝试将其中某些CSS属性移动到带有动画的CSS类中。

You also rely on jquery simply to do the selections in the init and select a custom container in the search. 您还仅依靠jquery在init中进行选择并在搜索中选择一个自定义容器。 The initial selections could be passed in as parameters, and the support for a custom class seems like it's a bit of a hack that was probably added in to support something after the fact (why? because of the function name animateSearch and then having support for any arbitrary class that may or may not have anything to do with search). 最初的选择可以作为参数传递,并且对自定义类的支持似乎有点animateSearch ,这可能是为了支持事后添加的东西(为什么?因为函数名称为animateSearch ,然后支持可能与搜索无关的任何任意类)。

Both those changes would improve "maintainability" but, again, ~70 is not necessarily a problem. 这些更改都将改善“可维护性”,但同样,〜70不一定是问题。 The scores are only important as they relate to the other code in an application and the comfort level of the developers. 分数仅是重要的,因为它们与应用程序中的其他代码以及开发人员的舒适度有关。

That said, this code is simple but could easily get out of hand as one off solutions are added. 也就是说,此代码很简单,但是随着添加一个解决方案,很容易失控。 A generic animation solution would be one abstraction. 通用动画解决方案将是一种抽象。 Using css animations and simply adding classes by convention or some app-level framework would be another; 使用CSS动画并根据约定或某些应用程序级别的框架简单地添加类是另一种方法。 eg some backbone component, angular directive or web component that managed their own states based off emptiness or otherwise. 例如一些骨干组件,角度指令或Web组件,它们根据空虚情况或其他方式管理自己的状态。 Those individual implementations would also very likely be just as "maintainable," score-wise, but it's limiting the scope and potential future creep that is important. 这些单独的实现也很可能会在分数方面保持“可维护性”,但是这限制了重要的范围和潜在的未来发展。

If a file never changes and never needs to be understood after being written then maintainability is irrelevant. 如果文件从未更改,并且在写入后也不需要理解,那么可维护性就无关紧要。 If a file will undergo many changes or needs to be fully understood in order to address all future code, then maintainability is a priority. 如果文件将进行很多更改或需要完全理解才能解决所有将来的代码,则优先考虑可维护性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM