@@ -516,379 +516,6 @@ <h2 class="panel-title">
516516 < script src ="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/highlight.min.js "> </ script >
517517 < script src ="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/languages/rust.min.js "> </ script >
518518 < script src ="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.12/angular.min.js "> </ script >
519- < script >
520- ( function ( ) {
521- var md = window . markdownit ( {
522- html : true ,
523- linkify : true ,
524- typographer : true ,
525- highlight : function ( str , lang ) {
526- if ( lang && hljs . getLanguage ( lang ) ) {
527- try {
528- return '<pre class="hljs"><code>' +
529- hljs . highlight ( lang , str , true ) . value +
530- '</code></pre>' ;
531- } catch ( __ ) { }
532- }
533-
534- return '<pre class="hljs"><code>' + md . utils . escapeHtml ( str ) + '</code></pre>' ;
535- }
536- } ) ;
537-
538- function scrollToLint ( lintId ) {
539- var target = document . getElementById ( lintId ) ;
540- if ( ! target ) {
541- return ;
542- }
543- target . scrollIntoView ( ) ;
544- }
545-
546- function scrollToLintByURL ( $scope ) {
547- var removeListener = $scope . $on ( 'ngRepeatFinished' , function ( ngRepeatFinishedEvent ) {
548- scrollToLint ( window . location . hash . slice ( 1 ) ) ;
549- removeListener ( ) ;
550- } ) ;
551- }
552-
553- function selectGroup ( $scope , selectedGroup ) {
554- var groups = $scope . groups ;
555- for ( var group in groups ) {
556- if ( groups . hasOwnProperty ( group ) ) {
557- if ( group === selectedGroup ) {
558- groups [ group ] = true ;
559- } else {
560- groups [ group ] = false ;
561- }
562- }
563- }
564- }
565-
566- angular . module ( "clippy" , [ ] )
567- . filter ( 'markdown' , function ( $sce ) {
568- return function ( text ) {
569- return $sce . trustAsHtml (
570- md . render ( text || '' )
571- // Oh deer, what a hack :O
572- . replace ( '<table' , '<table class="table"' )
573- ) ;
574- } ;
575- } )
576- . directive ( 'themeDropdown' , function ( $document ) {
577- return {
578- restrict : 'A' ,
579- link : function ( $scope , $element , $attr ) {
580- $element . bind ( 'click' , function ( ) {
581- $element . toggleClass ( 'open' ) ;
582- $element . addClass ( 'open-recent' ) ;
583- } ) ;
584-
585- $document . bind ( 'click' , function ( ) {
586- if ( ! $element . hasClass ( 'open-recent' ) ) {
587- $element . removeClass ( 'open' ) ;
588- }
589- $element . removeClass ( 'open-recent' ) ;
590- } )
591- }
592- }
593- } )
594- . directive ( 'filterDropdown' , function ( $document ) {
595- return {
596- restrict : 'A' ,
597- link : function ( $scope , $element , $attr ) {
598- $element . bind ( 'click' , function ( event ) {
599- if ( event . target . closest ( 'button' ) ) {
600- $element . toggleClass ( 'open' ) ;
601- } else {
602- $element . addClass ( 'open' ) ;
603- }
604- $element . addClass ( 'open-recent' ) ;
605- } ) ;
606-
607- $document . bind ( 'click' , function ( ) {
608- if ( ! $element . hasClass ( 'open-recent' ) ) {
609- $element . removeClass ( 'open' ) ;
610- }
611- $element . removeClass ( 'open-recent' ) ;
612- } )
613- }
614- }
615- } )
616- . directive ( 'onFinishRender' , function ( $timeout ) {
617- return {
618- restrict : 'A' ,
619- link : function ( scope , element , attr ) {
620- if ( scope . $last === true ) {
621- $timeout ( function ( ) {
622- scope . $emit ( attr . onFinishRender ) ;
623- } ) ;
624- }
625- }
626- } ;
627- } )
628- . controller ( "lintList" , function ( $scope , $http , $timeout ) {
629- // Level filter
630- var LEVEL_FILTERS_DEFAULT = { allow : true , warn : true , deny : true , none : true } ;
631- $scope . levels = LEVEL_FILTERS_DEFAULT ;
632- $scope . byLevels = function ( lint ) {
633- return $scope . levels [ lint . level ] ;
634- } ;
635-
636- var GROUPS_FILTER_DEFAULT = {
637- cargo : true ,
638- complexity : true ,
639- correctness : true ,
640- deprecated : false ,
641- nursery : true ,
642- pedantic : true ,
643- perf : true ,
644- restriction : true ,
645- style : true ,
646- suspicious : true ,
647- } ;
648- $scope . groups = GROUPS_FILTER_DEFAULT ;
649- const THEMES_DEFAULT = {
650- light : "Light" ,
651- rust : "Rust" ,
652- coal : "Coal" ,
653- navy : "Navy" ,
654- ayu : "Ayu"
655- } ;
656- $scope . themes = THEMES_DEFAULT ;
657-
658- const DEFAULT_VERSION_FILTERS = {
659- ">=" : { enabled : false , version_str : "" } ,
660- "<=" : { enabled : false , version_str : "" } ,
661- "==" : { enabled : false , version_str : "" } ,
662- } ;
663- // Weird workaround to get a copy of the object
664- $scope . version_filters = JSON . parse ( JSON . stringify ( DEFAULT_VERSION_FILTERS ) ) ;
665- $scope . version_regex = new RegExp ( '\\d\.\\d{2}\.\\d' ) ;
666-
667- $scope . selectTheme = function ( theme ) {
668- setTheme ( theme , true ) ;
669- }
670-
671- $scope . toggleLevels = function ( value ) {
672- const levels = $scope . levels ;
673- for ( const key in levels ) {
674- if ( levels . hasOwnProperty ( key ) ) {
675- levels [ key ] = value ;
676- }
677- }
678- } ;
679-
680- $scope . toggleGroups = function ( value ) {
681- const groups = $scope . groups ;
682- for ( const key in groups ) {
683- if ( groups . hasOwnProperty ( key ) ) {
684- groups [ key ] = value ;
685- }
686- }
687- } ;
688-
689- $scope . selectedValuesCount = function ( obj ) {
690- return Object . values ( obj ) . filter ( x => x ) . length ;
691- }
692-
693- $scope . clearVersionFilters = function ( ) {
694- $scope . version_filters = JSON . parse ( JSON . stringify ( DEFAULT_VERSION_FILTERS ) ) ;
695- }
696-
697- $scope . versionSymbol = function ( ) {
698- const version_filters = $scope . version_filters ;
699- let filter = ">=" ;
700- for ( const key in version_filters ) {
701- if ( version_filters [ key ] ) {
702- filter = key ;
703- }
704- }
705-
706- return filter ;
707- }
708-
709- $scope . byVersion = function ( lint ) {
710- function validate_version_str ( ver ) {
711- return ver . length === 6 && $scope . version_regex . test ( ver ) ;
712- }
713-
714- function cmp_version ( ver1 , ver2 , filter ) {
715- // < 0: lint_version < version
716- // 0: equal
717- // > 0: lint_version > version
718- let result = ver1 . localeCompare ( ver2 , undefined , {
719- numeric : true ,
720- sensitivity : "base"
721- } ) ;
722-
723- // "==" gets the highest priority, since all filters are inclusive
724- return ( result === 0 ) || ( filter === ">=" && result > 0 ) || ( filter === "<=" && result < 0 ) ;
725- }
726-
727- let filters = $scope . version_filters ;
728-
729- // Strip the "pre " prefix for pre 1.29.0 lints
730- let lint_version = lint . version . startsWith ( "pre " ) ? lint . version . substring ( 4 , lint . version . length ) : lint . version ;
731-
732- for ( const filter in filters ) {
733- let version_str = filters [ filter ] . version_str ;
734-
735- // Skip the work for version strings with invalid lengths or characters
736- if ( ! filters [ filter ] . enabled || ! validate_version_str ( version_str ) ) {
737- continue ;
738- }
739-
740- let result = cmp_version ( lint_version , version_str , filter ) ;
741- if ( result && filter === "==" ) {
742- return true ;
743- } else if ( ! result ) {
744- return false ;
745- }
746-
747- let cmp_filter ;
748- if ( filter === ">=" ) {
749- cmp_filter = "<=" ;
750- } else {
751- cmp_filter = ">=" ;
752- }
753-
754- let cmp_version_str = filters [ cmp_filter ] . version_str ;
755- if ( ! filters [ cmp_filter ] . enabled || ! validate_version_str ( cmp_version_str ) ) {
756- return true ;
757- }
758-
759- return cmp_version ( lint_version , cmp_version_str , cmp_filter ) ;
760- }
761-
762- return true ;
763- }
764-
765- $scope . byGroups = function ( lint ) {
766- return $scope . groups [ lint . group ] ;
767- } ;
768-
769- $scope . bySearch = function ( lint , index , array ) {
770- let searchStr = $scope . search ;
771- // It can be `null` I haven't missed this value
772- if ( searchStr == null || searchStr . length < 3 ) {
773- return true ;
774- }
775- searchStr = searchStr . toLowerCase ( ) ;
776-
777- // Search by id
778- if ( lint . id . indexOf ( searchStr . replace ( "-" , "_" ) ) !== - 1 ) {
779- return true ;
780- }
781-
782- // Search the description
783- // The use of `for`-loops instead of `foreach` enables us to return early
784- let terms = searchStr . split ( " " ) ;
785- let docsLowerCase = lint . docs . toLowerCase ( ) ;
786- for ( index = 0 ; index < terms . length ; index ++ ) {
787- // This is more likely and will therefor be checked first
788- if ( docsLowerCase . indexOf ( terms [ index ] ) !== - 1 ) {
789- continue ;
790- }
791-
792- if ( lint . id . indexOf ( terms [ index ] ) !== - 1 ) {
793- continue ;
794- }
795-
796- return false ;
797- }
798-
799- return true ;
800- }
801-
802- // Get data
803- $scope . open = { } ;
804- $scope . loading = true ;
805- // This will be used to jump into the source code of the version that this documentation is for.
806- $scope . docVersion = window . location . pathname . split ( '/' ) [ 2 ] || "master" ;
807-
808- if ( window . location . hash . length > 1 ) {
809- $scope . search = window . location . hash . slice ( 1 ) ;
810- $scope . open [ window . location . hash . slice ( 1 ) ] = true ;
811- scrollToLintByURL ( $scope ) ;
812- }
813-
814- $http . get ( './lints.json' )
815- . success ( function ( data ) {
816- $scope . data = data ;
817- $scope . loading = false ;
818-
819- var selectedGroup = getQueryVariable ( "sel" ) ;
820- if ( selectedGroup ) {
821- selectGroup ( $scope , selectedGroup . toLowerCase ( ) ) ;
822- }
823-
824- scrollToLintByURL ( $scope ) ;
825-
826- setTimeout ( function ( ) {
827- var el = document . getElementById ( 'filter-input' ) ;
828- if ( el ) { el . focus ( ) }
829- } , 0 ) ;
830- } )
831- . error ( function ( data ) {
832- $scope . error = data ;
833- $scope . loading = false ;
834- } ) ;
835-
836- window . addEventListener ( 'hashchange' , function ( ) {
837- // trigger re-render
838- $timeout ( function ( ) {
839- $scope . levels = LEVEL_FILTERS_DEFAULT ;
840- $scope . search = window . location . hash . slice ( 1 ) ;
841- $scope . open [ window . location . hash . slice ( 1 ) ] = true ;
842-
843- scrollToLintByURL ( $scope ) ;
844- } ) ;
845- return true ;
846- } , false ) ;
847- } ) ;
848- } ) ( ) ;
849-
850- function getQueryVariable ( variable ) {
851- var query = window . location . search . substring ( 1 ) ;
852- var vars = query . split ( '&' ) ;
853- for ( var i = 0 ; i < vars . length ; i ++ ) {
854- var pair = vars [ i ] . split ( '=' ) ;
855- if ( decodeURIComponent ( pair [ 0 ] ) == variable ) {
856- return decodeURIComponent ( pair [ 1 ] ) ;
857- }
858- }
859- }
860-
861- function setTheme ( theme , store ) {
862- let enableHighlight = false ;
863- let enableNight = false ;
864- let enableAyu = false ;
865-
866- if ( theme == "ayu" ) {
867- enableAyu = true ;
868- } else if ( theme == "coal" || theme == "navy" ) {
869- enableNight = true ;
870- } else if ( theme == "rust" ) {
871- enableHighlight = true ;
872- } else {
873- enableHighlight = true ;
874- // this makes sure that an unknown theme request gets set to a known one
875- theme = "light" ;
876- }
877- document . getElementsByTagName ( "body" ) [ 0 ] . className = theme ;
878-
879- document . getElementById ( "styleHighlight" ) . disabled = ! enableHighlight ;
880- document . getElementById ( "styleNight" ) . disabled = ! enableNight ;
881- document . getElementById ( "styleAyu" ) . disabled = ! enableAyu ;
882-
883- if ( store ) {
884- try {
885- localStorage . setItem ( 'clippy-lint-list-theme' , theme ) ;
886- } catch ( e ) { }
887- }
888- }
889-
890- // loading the theme after the initial load
891- setTheme ( localStorage . getItem ( 'clippy-lint-list-theme' ) , false ) ;
892- </ script >
519+ < script src ="script.js "> </ script >
893520</ body >
894521</ html >
0 commit comments