fork/rules_rust
git clone https://git.julia.blue/fork/rules_rust
482a21cf
gh-pages
1<!DOCTYPE HTML > 2< html lang ="en "class ="light sidebar-visible "dir ="ltr "> 3< head > 4<!-- Book generated using mdBook --> 5< meta charset ="UTF-8 "> 6< title > clippy - rules_rust</ title > 7 8 9<!-- Custom HTML head --> 10 11< meta name ="description "content =""> 12< meta name ="viewport "content ="width=device-width, initial-scale=1 "> 13< meta name ="theme-color "content ="#ffffff "> 14 15< link rel ="icon "href ="favicon.svg "> 16< link rel ="shortcut icon "href ="favicon.png "> 17< link rel ="stylesheet "href ="css/variables.css "> 18< link rel ="stylesheet "href ="css/general.css "> 19< link rel ="stylesheet "href ="css/chrome.css "> 20< link rel ="stylesheet "href ="css/print.css "media ="> 21 22<!-- Fonts --> 23< link rel ="stylesheet "href ="FontAwesome/css/font-awesome.css "> 24< link rel ="stylesheet "href ="fonts/fonts.css "> 25 26<!-- Highlight.js Stylesheets --> 27< link rel ="stylesheet "href ="highlight.css "> 28< link rel ="stylesheet "href ="tomorrow-night.css "> 29< link rel ="stylesheet "href ="ayu-highlight.css "> 30 31<!-- Custom theme stylesheets --> 32 33 34<!-- Provide site root to javascript --> 35< script > 36var path_to_root = "" ; 37var default_theme = window . matchMedia ( "(prefers-color-scheme: dark)" ). matches ?"navy" :"light" ; 38</ script > 39<!-- Start loading toc.js asap --> 40< script src ="toc.js "></ script > 41</ head > 42< body > 43< div id ="body-container "> 44<!-- Work around some values being stored in localStorage wrapped in quotes --> 45< script > 46try { 47var theme = localStorage . getItem ( 'mdbook-theme' ); 48var sidebar = localStorage . getItem ( 'mdbook-sidebar' ); 49 50if ( theme . startsWith ( '"' ) && theme . endsWith ( '"' )) { 51localStorage . setItem ( 'mdbook-theme' , theme . slice ( 1 , theme . length - 1 )); 52} 53 54if ( sidebar . startsWith ( '"' ) && sidebar . endsWith ( '"' )) { 55localStorage . setItem ( 'mdbook-sidebar' , sidebar . slice ( 1 , sidebar . length - 1 )); 56} 57} catch ( e ) { } 58</ script > 59 60<!-- Set the theme before any content is loaded, prevents flash --> 61< script > 62var theme ; 63try { theme = localStorage . getItem ( 'mdbook-theme' ); } catch ( e ) { } 64if ( theme === null || theme === undefined ) { theme = default_theme ; } 65const html = document . documentElement ; 66html . classList . remove ( 'light' ) 67html . classList . add ( theme ); 68html . classList . add ( "js" ); 69</ script > 70 71< input type ="checkbox "id ="sidebar-toggle-anchor "class ="hidden "> 72 73<!-- Hide / unhide sidebar before it is displayed --> 74< script > 75var sidebar = null ; 76var sidebar_toggle = document . getElementById ( "sidebar-toggle-anchor" ); 77if ( document . body . clientWidth >= 1080 ) { 78try { sidebar = localStorage . getItem ( 'mdbook-sidebar' ); } catch ( e ) { } 79sidebar = sidebar || 'visible' ; 80} else { 81sidebar = 'hidden' ; 82} 83sidebar_toggle . checked = sidebar === 'visible' ; 84html . classList . remove ( 'sidebar-visible' ); 85html . classList . add ( "sidebar-" + sidebar ); 86</ script > 87 88< nav id ="sidebar "class ="sidebar "aria-label ="Table of contents "> 89<!-- populated by js --> 90< mdbook-sidebar-scrollbox class ="sidebar-scrollbox "></ mdbook-sidebar-scrollbox > 91< noscript > 92< iframe class ="sidebar-iframe-outer "src ="toc.html "></ iframe > 93</ noscript > 94< div id ="sidebar-resize-handle "class ="sidebar-resize-handle "> 95< div class ="sidebar-resize-indicator "></ div > 96</ div > 97</ nav > 98 99< div id ="page-wrapper "class ="page-wrapper "> 100 101< div class ="page "> 102< div id ="menu-bar-hover-placeholder "></ div > 103< div id ="menu-bar "class ="menu-bar sticky "> 104< div class ="left-buttons "> 105< label id ="sidebar-toggle "class ="icon-button "for ="sidebar-toggle-anchor "title ="Toggle Table of Contents "aria-label ="Toggle Table of Contents "aria-controls ="sidebar "> 106< i class ="fa fa-bars "></ i > 107</ label > 108< button id ="theme-toggle "class ="icon-button "type ="button "title ="Change theme "aria-label ="Change theme "aria-haspopup ="true "aria-expanded ="false "aria-controls ="theme-list "> 109< i class ="fa fa-paint-brush "></ i > 110</ button > 111< ul id ="theme-list "class ="theme-popup "aria-label ="Themes "role ="menu "> 112< li role ="none ">< button role ="menuitem "class ="theme "id ="light "> Light</ button ></ li > 113< li role ="none ">< button role ="menuitem "class ="theme "id ="rust "> Rust</ button ></ li > 114< li role ="none ">< button role ="menuitem "class ="theme "id ="coal "> Coal</ button ></ li > 115< li role ="none ">< button role ="menuitem "class ="theme "id ="navy "> Navy</ button ></ li > 116< li role ="none ">< button role ="menuitem "class ="theme "id ="ayu "> Ayu</ button ></ li > 117</ ul > 118< button id ="search-toggle "class ="icon-button "type ="button "title ="Search. (Shortkey: s) "aria-label ="Toggle Searchbar "aria-expanded ="false "aria-keyshortcuts ="S "aria-controls ="searchbar "> 119< i class ="fa fa-search "></ i > 120</ button > 121</ div > 122 123< h1 class ="menu-title "> rules_rust</ h1 > 124 125< div class ="right-buttons "> 126< a href ="print.html "title ="Print this book "aria-label ="Print this book "> 127< i id ="print-button "class ="fa fa-print "></ i > 128</ a > 129< a href ="https://github.com/bazelbuild/rules_rust "title ="Git repository "aria-label ="Git repository "> 130< i id ="git-repository-button "class ="fa fa-github "></ i > 131</ a > 132 133</ div > 134</ div > 135 136< div id ="search-wrapper "class ="hidden "> 137< form id ="searchbar-outer "class ="searchbar-outer "> 138< input type ="search "id ="searchbar "name ="searchbar "placeholder ="Search this book ... "aria-controls ="searchresults-outer "aria-describedby ="searchresults-header "> 139</ form > 140< div id ="searchresults-outer "class ="searchresults-outer hidden "> 141< div id ="searchresults-header "class ="searchresults-header "></ div > 142< ul id ="searchresults "> 143</ ul > 144</ div > 145</ div > 146 147<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM --> 148< script > 149document . getElementById ( 'sidebar-toggle' ). setAttribute ( 'aria-expanded' , sidebar === 'visible' ); 150document . getElementById ( 'sidebar' ). setAttribute ( 'aria-hidden' , sidebar !== 'visible' ); 151Array . from ( document . querySelectorAll ( '#sidebar a' )). forEach ( function ( link ) { 152link . setAttribute ( 'tabIndex' , sidebar === 'visible' ?0 :- 1 ); 153}); 154</ script > 155 156< div id ="content "class ="content "> 157< main > 158<!-- Generated with Stardoc: http://skydoc.bazel.build --> 159< h1 id ="rust-clippy ">< a class ="header "href ="#rust-clippy "> Rust Clippy</ a ></ h1 > 160< ul > 161< li >< a href ="#rust_clippy "> rust_clippy</ a ></ li > 162< li >< a href ="#rust_clippy_aspect "> rust_clippy_aspect</ a ></ li > 163</ ul > 164< h2 id ="overview ">< a class ="header "href ="#overview "> Overview</ a ></ h2 > 165< p >< a href ="https://github.com/rust-lang/rust-clippy#readme "> Clippy</ a > is a tool for catching common mistakes in Rust code and improving it. An 166expansive list of lints and the justification can be found in their< a href ="https://rust-lang.github.io/rust-clippy/ "> documentation</ a > .</ p > 167< h3 id ="setup ">< a class ="header "href ="#setup "> Setup</ a ></ h3 > 168< p > Simply add the following to the< code > .bazelrc</ code > file in the root of your workspace:</ p > 169< pre >< code class ="language-text "> build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect 170build --output_groups=+clippy_checks 171</ code ></ pre > 172< p > This will enable clippy on all< a href ="./defs.html "> Rust targets</ a > .</ p > 173< p > Note that targets tagged with< code > no-clippy</ code > will not perform clippy checks</ p > 174< p > To use a local clippy.toml, add the following flag to your< code > .bazelrc</ code > . Note that due to 175the upstream implementation of clippy, this file must be named either< code > .clippy.toml</ code > or 176< code > clippy.toml</ code > . Using a custom config file requires Rust 1.34.0 or newer.</ p > 177< pre >< code class ="language-text "> build --@rules_rust//rust/settings:clippy.toml=//:clippy.toml 178</ code ></ pre > 179< p >< a id ="rust_clippy "></ a ></ p > 180< h2 id ="rust_clippy ">< a class ="header "href ="#rust_clippy "> rust_clippy</ a ></ h2 > 181< pre > 182rust_clippy(< a href ="#rust_clippy-name "> name</ a > ,< a href ="#rust_clippy-deps "> deps</ a > ) 183</ pre > 184< p > Executes the clippy checker on a specific target.</ p > 185< p > Similar to< code > rust_clippy_aspect</ code > , but allows specifying a list of dependencies within the build system.</ p > 186< p > For example, given the following example targets:</ p > 187< pre >< code class ="language-python "> load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") 188 189rust_library( 190 name = "hello_lib", 191 srcs = ["src/lib.rs"], 192) 193 194rust_test( 195 name = "greeting_test", 196 srcs = ["tests/greeting.rs"], 197 deps = [":hello_lib"], 198) 199</ code ></ pre > 200< p > Rust clippy can be set as a build target with the following:</ p > 201< pre >< code class ="language-python "> load("@rules_rust//rust:defs.bzl", "rust_clippy") 202 203rust_clippy( 204 name = "hello_library_clippy", 205 testonly = True, 206 deps = [ 207 ":hello_lib", 208 ":greeting_test", 209 ], 210) 211</ code ></ pre > 212< p >< strong > ATTRIBUTES</ strong ></ p > 213< div class ="table-wrapper ">< table >< thead >< tr >< th style ="text-align: left "> Name</ th >< th style ="text-align: left "> Description</ th >< th style ="text-align: left "> Type</ th >< th style ="text-align: left "> Mandatory</ th >< th style ="text-align: left "> Default</ th ></ tr ></ thead >< tbody > 214< tr >< td style ="text-align: left ">< a id ="rust_clippy-name "></ a > name</ td >< td style ="text-align: left "> A unique name for this target.</ td >< td style ="text-align: left ">< a href ="https://bazel.build/concepts/labels#target-names "> Name</ a ></ td >< td style ="text-align: left "> required</ td >< td style ="text-align: left "></ td ></ tr > 215< tr >< td style ="text-align: left ">< a id ="rust_clippy-deps "></ a > deps</ td >< td style ="text-align: left "> Rust targets to run clippy on.</ td >< td style ="text-align: left ">< a href ="https://bazel.build/concepts/labels "> List of labels</ a ></ td >< td style ="text-align: left "> optional</ td >< td style ="text-align: left ">< code > []</ code ></ td ></ tr > 216</ tbody ></ table > 217</ div > 218< p >< a id ="rust_clippy_aspect "></ a ></ p > 219< h2 id ="rust_clippy_aspect ">< a class ="header "href ="#rust_clippy_aspect "> rust_clippy_aspect</ a ></ h2 > 220< pre > 221rust_clippy_aspect(< a href ="#rust_clippy_aspect-name "> name</ a > ) 222</ pre > 223< p > Executes the clippy checker on specified targets.</ p > 224< p > This aspect applies to existing rust_library, rust_test, and rust_binary rules.</ p > 225< p > As an example, if the following is defined in< code > examples/hello_lib/BUILD.bazel</ code > :</ p > 226< pre >< code class ="language-python "> load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") 227 228rust_library( 229 name = "hello_lib", 230 srcs = ["src/lib.rs"], 231) 232 233rust_test( 234 name = "greeting_test", 235 srcs = ["tests/greeting.rs"], 236 deps = [":hello_lib"], 237) 238</ code ></ pre > 239< p > Then the targets can be analyzed with clippy using the following command:</ p > 240< pre >< code class ="language-output "> $ bazel build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect --output_groups=clippy_checks //hello_lib:all 241</ code ></ pre > 242< p >< strong > ASPECT ATTRIBUTES</ strong ></ p > 243< p >< strong > ATTRIBUTES</ strong ></ p > 244< div class ="table-wrapper ">< table >< thead >< tr >< th style ="text-align: left "> Name</ th >< th style ="text-align: left "> Description</ th >< th style ="text-align: left "> Type</ th >< th style ="text-align: left "> Mandatory</ th >< th style ="text-align: left "> Default</ th ></ tr ></ thead >< tbody > 245< tr >< td style ="text-align: left ">< a id ="rust_clippy_aspect-name "></ a > name</ td >< td style ="text-align: left "> A unique name for this target.</ td >< td style ="text-align: left ">< a href ="https://bazel.build/concepts/labels#target-names "> Name</ a ></ td >< td style ="text-align: left "> required</ td >< td style ="text-align: left "></ td ></ tr > 246</ tbody ></ table > 247</ div > 248</ main > 249 250< nav class ="nav-wrapper "aria-label ="Page navigation "> 251<!-- Mobile navigation buttons --> 252< a rel ="prev "href ="rust_doc.html "class ="mobile-nav-chapters previous "title ="Previous chapter "aria-label ="Previous chapter "aria-keyshortcuts ="Left "> 253< i class ="fa fa-angle-left "></ i > 254</ a > 255 256< a rel ="next prefetch "href ="rust_fmt.html "class ="mobile-nav-chapters next "title ="Next chapter "aria-label ="Next chapter "aria-keyshortcuts ="Right "> 257< i class ="fa fa-angle-right "></ i > 258</ a > 259 260< div style ="clear: both "></ div > 261</ nav > 262</ div > 263</ div > 264 265< nav class ="nav-wide-wrapper "aria-label ="Page navigation "> 266< a rel ="prev "href ="rust_doc.html "class ="nav-chapters previous "title ="Previous chapter "aria-label ="Previous chapter "aria-keyshortcuts ="Left "> 267< i class ="fa fa-angle-left "></ i > 268</ a > 269 270< a rel ="next prefetch "href ="rust_fmt.html "class ="nav-chapters next "title ="Next chapter "aria-label ="Next chapter "aria-keyshortcuts ="Right "> 271< i class ="fa fa-angle-right "></ i > 272</ a > 273</ nav > 274 275</ div > 276 277 278 279 280< script > 281window . playground_copyable = true ; 282</ script > 283 284 285< script src ="elasticlunr.min.js "></ script > 286< script src ="mark.min.js "></ script > 287< script src ="searcher.js "></ script > 288 289< script src ="clipboard.min.js "></ script > 290< script src ="highlight.js "></ script > 291< script src ="book.js "></ script > 292 293<!-- Custom JS scripts --> 294 295 296</ div > 297</ body > 298</ html >