| |
| <!doctype html> |
| <html lang="en" class="no-js"> |
| <head> |
| |
| <meta charset="utf-8"> |
| <meta name="viewport" content="width=device-width,initial-scale=1"> |
| |
| |
| |
| <link rel="canonical" href="https://pinterest.github.io/ktlint/0.48.0/faq/"> |
| |
| |
| <link rel="prev" href="../extensions/badge/"> |
| |
| |
| <link rel="next" href="../contributing/overview/"> |
| |
| <link rel="icon" href="../assets/images/favicon.ico"> |
| <meta name="generator" content="mkdocs-1.4.2, mkdocs-material-9.1.7"> |
| |
| |
| |
| <title>FAQ - Ktlint</title> |
| |
| |
| |
| <link rel="stylesheet" href="../assets/stylesheets/main.ded33207.min.css"> |
| |
| |
| <link rel="stylesheet" href="../assets/stylesheets/palette.a0c5b2b5.min.css"> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> |
| <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback"> |
| <style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style> |
| |
| |
| |
| <script>__md_scope=new URL("..",location),__md_hash=e=>[...e].reduce((e,_)=>(e<<5)-e+_.charCodeAt(0),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script> |
| |
| |
| |
| |
| |
| |
| </head> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <body dir="ltr" data-md-color-scheme="default" data-md-color-primary="pink" data-md-color-accent="indigo"> |
| |
| |
| |
| <script>var palette=__md_get("__palette");if(palette&&"object"==typeof palette.color)for(var key of Object.keys(palette.color))document.body.setAttribute("data-md-color-"+key,palette.color[key])</script> |
| |
| <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off"> |
| <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off"> |
| <label class="md-overlay" for="__drawer"></label> |
| <div data-md-component="skip"> |
| |
| |
| <a href="#why-should-i-use-ktlint" class="md-skip"> |
| Skip to content |
| </a> |
| |
| </div> |
| <div data-md-component="announce"> |
| |
| </div> |
| |
| <div data-md-color-scheme="default" data-md-component="outdated" hidden> |
| |
| <aside class="md-banner md-banner--warning"> |
| <div class="md-banner__inner md-grid md-typeset"> |
| |
| You're not viewing the latest version. |
| <a href="../.."> |
| <strong>Click here to go to latest.</strong> |
| </a> |
| |
| </div> |
| <script>var el=document.querySelector("[data-md-component=outdated]"),outdated=__md_get("__outdated",sessionStorage);!0===outdated&&el&&(el.hidden=!1)</script> |
| </aside> |
| |
| </div> |
| |
| |
| |
| |
| |
| |
| <header class="md-header md-header--shadow md-header--lifted" data-md-component="header"> |
| <nav class="md-header__inner md-grid" aria-label="Header"> |
| <a href=".." title="Ktlint" class="md-header__button md-logo" aria-label="Ktlint" data-md-component="logo"> |
| |
| |
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54Z"/></svg> |
| |
| </a> |
| <label class="md-header__button md-icon" for="__drawer"> |
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg> |
| </label> |
| <div class="md-header__title" data-md-component="header-title"> |
| <div class="md-header__ellipsis"> |
| <div class="md-header__topic"> |
| <span class="md-ellipsis"> |
| Ktlint |
| </span> |
| </div> |
| <div class="md-header__topic" data-md-component="header-topic"> |
| <span class="md-ellipsis"> |
| |
| FAQ |
| |
| </span> |
| </div> |
| </div> |
| </div> |
| |
| <form class="md-header__option" data-md-component="palette"> |
| |
| |
| |
| |
| <input class="md-option" data-md-color-media="(prefers-color-scheme: light)" data-md-color-scheme="default" data-md-color-primary="pink" data-md-color-accent="indigo" aria-label="Switch to dark mode" type="radio" name="__palette" id="__palette_1"> |
| |
| <label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_2" hidden> |
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a4 4 0 0 0-4 4 4 4 0 0 0 4 4 4 4 0 0 0 4-4 4 4 0 0 0-4-4m0 10a6 6 0 0 1-6-6 6 6 0 0 1 6-6 6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69Z"/></svg> |
| </label> |
| |
| |
| |
| |
| |
| <input class="md-option" data-md-color-media="(prefers-color-scheme: dark)" data-md-color-scheme="slate" data-md-color-primary="pink" data-md-color-accent="indigo" aria-label="Switch to light mode" type="radio" name="__palette" id="__palette_2"> |
| |
| <label class="md-header__button md-icon" title="Switch to light mode" for="__palette_1" hidden> |
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 18c-.89 0-1.74-.2-2.5-.55C11.56 16.5 13 14.42 13 12c0-2.42-1.44-4.5-3.5-5.45C10.26 6.2 11.11 6 12 6a6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69Z"/></svg> |
| </label> |
| |
| |
| </form> |
| |
| |
| |
| <label class="md-header__button md-icon" for="__search"> |
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg> |
| </label> |
| <div class="md-search" data-md-component="search" role="dialog"> |
| <label class="md-search__overlay" for="__search"></label> |
| <div class="md-search__inner" role="search"> |
| <form class="md-search__form" name="search"> |
| <input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required> |
| <label class="md-search__icon md-icon" for="__search"> |
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg> |
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg> |
| </label> |
| <nav class="md-search__options" aria-label="Search"> |
| |
| <a href="javascript:void(0)" class="md-search__icon md-icon" title="Share" aria-label="Share" data-clipboard data-clipboard-text="" data-md-component="search-share" tabindex="-1"> |
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7 0-.24-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9a3 3 0 0 0-3 3 3 3 0 0 0 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.15c-.05.21-.08.43-.08.66 0 1.61 1.31 2.91 2.92 2.91 1.61 0 2.92-1.3 2.92-2.91A2.92 2.92 0 0 0 18 16.08Z"/></svg> |
| </a> |
| |
| <button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1"> |
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z"/></svg> |
| </button> |
| </nav> |
| |
| <div class="md-search__suggest" data-md-component="search-suggest"></div> |
| |
| </form> |
| <div class="md-search__output"> |
| <div class="md-search__scrollwrap" data-md-scrollfix> |
| <div class="md-search-result" data-md-component="search-result"> |
| <div class="md-search-result__meta"> |
| Initializing search |
| </div> |
| <ol class="md-search-result__list" role="presentation"></ol> |
| </div> |
| </div> |
| </div> |
| </div> |
| </div> |
| |
| |
| <div class="md-header__source"> |
| <a href="https://github.com/pinterest/ktlint" title="Go to repository" class="md-source" data-md-component="source"> |
| <div class="md-source__icon md-icon"> |
| |
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 2A10 10 0 0 0 2 12c0 4.42 2.87 8.17 6.84 9.5.5.08.66-.23.66-.5v-1.69c-2.77.6-3.36-1.34-3.36-1.34-.46-1.16-1.11-1.47-1.11-1.47-.91-.62.07-.6.07-.6 1 .07 1.53 1.03 1.53 1.03.87 1.52 2.34 1.07 2.91.83.09-.65.35-1.09.63-1.34-2.22-.25-4.55-1.11-4.55-4.92 0-1.11.38-2 1.03-2.71-.1-.25-.45-1.29.1-2.64 0 0 .84-.27 2.75 1.02.79-.22 1.65-.33 2.5-.33.85 0 1.71.11 2.5.33 1.91-1.29 2.75-1.02 2.75-1.02.55 1.35.2 2.39.1 2.64.65.71 1.03 1.6 1.03 2.71 0 3.82-2.34 4.66-4.57 4.91.36.31.69.92.69 1.85V21c0 .27.16.59.67.5C19.14 20.16 22 16.42 22 12A10 10 0 0 0 12 2Z"/></svg> |
| </div> |
| <div class="md-source__repository"> |
| pinterest/ktlint |
| </div> |
| </a> |
| </div> |
| |
| </nav> |
| |
| |
| |
| <nav class="md-tabs" aria-label="Tabs" data-md-component="tabs"> |
| <div class="md-grid"> |
| <ul class="md-tabs__list"> |
| |
| |
| |
| |
| |
| |
| <li class="md-tabs__item"> |
| <a href=".." class="md-tabs__link"> |
| Home |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-tabs__item"> |
| <a href="../install/overview/" class="md-tabs__link"> |
| Installation |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-tabs__item"> |
| <a href="../rules/standard/" class="md-tabs__link"> |
| Rules |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-tabs__item"> |
| <a href="../extensions/custom-rule-set/" class="md-tabs__link"> |
| Extensions |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-tabs__item"> |
| <a href="./" class="md-tabs__link md-tabs__link--active"> |
| FAQ |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-tabs__item"> |
| <a href="../contributing/overview/" class="md-tabs__link"> |
| Contributing |
| </a> |
| </li> |
| |
| |
| |
| </ul> |
| </div> |
| </nav> |
| |
| |
| </header> |
| |
| <div class="md-container" data-md-component="container"> |
| |
| |
| |
| |
| <main class="md-main" data-md-component="main"> |
| <div class="md-main__inner md-grid"> |
| |
| |
| |
| <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" > |
| <div class="md-sidebar__scrollwrap"> |
| <div class="md-sidebar__inner"> |
| |
| |
| |
| |
| |
| <nav class="md-nav md-nav--primary md-nav--lifted" aria-label="Navigation" data-md-level="0"> |
| <label class="md-nav__title" for="__drawer"> |
| <a href=".." title="Ktlint" class="md-nav__button md-logo" aria-label="Ktlint" data-md-component="logo"> |
| |
| |
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54Z"/></svg> |
| |
| </a> |
| Ktlint |
| </label> |
| |
| <div class="md-nav__source"> |
| <a href="https://github.com/pinterest/ktlint" title="Go to repository" class="md-source" data-md-component="source"> |
| <div class="md-source__icon md-icon"> |
| |
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 2A10 10 0 0 0 2 12c0 4.42 2.87 8.17 6.84 9.5.5.08.66-.23.66-.5v-1.69c-2.77.6-3.36-1.34-3.36-1.34-.46-1.16-1.11-1.47-1.11-1.47-.91-.62.07-.6.07-.6 1 .07 1.53 1.03 1.53 1.03.87 1.52 2.34 1.07 2.91.83.09-.65.35-1.09.63-1.34-2.22-.25-4.55-1.11-4.55-4.92 0-1.11.38-2 1.03-2.71-.1-.25-.45-1.29.1-2.64 0 0 .84-.27 2.75 1.02.79-.22 1.65-.33 2.5-.33.85 0 1.71.11 2.5.33 1.91-1.29 2.75-1.02 2.75-1.02.55 1.35.2 2.39.1 2.64.65.71 1.03 1.6 1.03 2.71 0 3.82-2.34 4.66-4.57 4.91.36.31.69.92.69 1.85V21c0 .27.16.59.67.5C19.14 20.16 22 16.42 22 12A10 10 0 0 0 12 2Z"/></svg> |
| </div> |
| <div class="md-source__repository"> |
| pinterest/ktlint |
| </div> |
| </a> |
| </div> |
| |
| <ul class="md-nav__list" data-md-scrollfix> |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item"> |
| <a href=".." class="md-nav__link"> |
| Home |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item md-nav__item--nested"> |
| |
| |
| |
| |
| |
| |
| <input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_2" > |
| |
| |
| |
| <label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0"> |
| Installation |
| <span class="md-nav__icon md-icon"></span> |
| </label> |
| |
| <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_2_label" aria-expanded="false"> |
| <label class="md-nav__title" for="__nav_2"> |
| <span class="md-nav__icon md-icon"></span> |
| Installation |
| </label> |
| <ul class="md-nav__list" data-md-scrollfix> |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item"> |
| <a href="../install/overview/" class="md-nav__link"> |
| Overview |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item"> |
| <a href="../install/cli/" class="md-nav__link"> |
| Command line |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item"> |
| <a href="../install/integrations/" class="md-nav__link"> |
| Integrations |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item"> |
| <a href="../install/snapshot-build/" class="md-nav__link"> |
| Snapshot build |
| </a> |
| </li> |
| |
| |
| |
| |
| </ul> |
| </nav> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item md-nav__item--nested"> |
| |
| |
| |
| |
| |
| |
| <input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_3" > |
| |
| |
| |
| <label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0"> |
| Rules |
| <span class="md-nav__icon md-icon"></span> |
| </label> |
| |
| <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false"> |
| <label class="md-nav__title" for="__nav_3"> |
| <span class="md-nav__icon md-icon"></span> |
| Rules |
| </label> |
| <ul class="md-nav__list" data-md-scrollfix> |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item"> |
| <a href="../rules/standard/" class="md-nav__link"> |
| Standard rules |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item"> |
| <a href="../rules/experimental/" class="md-nav__link"> |
| Experimental rules |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item"> |
| <a href="../rules/dependencies/" class="md-nav__link"> |
| Dependencies |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item"> |
| <a href="../rules/configuration-ktlint/" class="md-nav__link"> |
| KtLint configuration |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item"> |
| <a href="../rules/configuration-intellij-idea/" class="md-nav__link"> |
| IntelliJ IDEA configuration |
| </a> |
| </li> |
| |
| |
| |
| |
| </ul> |
| </nav> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item md-nav__item--nested"> |
| |
| |
| |
| |
| |
| |
| <input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_4" > |
| |
| |
| |
| <label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0"> |
| Extensions |
| <span class="md-nav__icon md-icon"></span> |
| </label> |
| |
| <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="false"> |
| <label class="md-nav__title" for="__nav_4"> |
| <span class="md-nav__icon md-icon"></span> |
| Extensions |
| </label> |
| <ul class="md-nav__list" data-md-scrollfix> |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item"> |
| <a href="../extensions/custom-rule-set/" class="md-nav__link"> |
| Custom rule set |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item"> |
| <a href="../extensions/custom-reporter/" class="md-nav__link"> |
| Custom reporter |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item"> |
| <a href="../extensions/badge/" class="md-nav__link"> |
| Badge |
| </a> |
| </li> |
| |
| |
| |
| |
| </ul> |
| </nav> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item md-nav__item--active"> |
| |
| <input class="md-nav__toggle md-toggle" type="checkbox" id="__toc"> |
| |
| |
| |
| <label class="md-nav__link md-nav__link--active" for="__toc"> |
| FAQ |
| <span class="md-nav__icon md-icon"></span> |
| </label> |
| |
| <a href="./" class="md-nav__link md-nav__link--active"> |
| FAQ |
| </a> |
| |
| |
| |
| <nav class="md-nav md-nav--secondary" aria-label="Table of contents"> |
| |
| |
| |
| |
| <label class="md-nav__title" for="__toc"> |
| <span class="md-nav__icon md-icon"></span> |
| Table of contents |
| </label> |
| <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix> |
| |
| <li class="md-nav__item"> |
| <a href="#why-should-i-use-ktlint" class="md-nav__link"> |
| Why should I use ktlint? |
| </a> |
| |
| </li> |
| |
| <li class="md-nav__item"> |
| <a href="#can-i-have-my-own-rules-on-top-of-ktlint" class="md-nav__link"> |
| Can I have my own rules on top of ktlint? |
| </a> |
| |
| </li> |
| |
| <li class="md-nav__item"> |
| <a href="#how-do-i-suppress-errors-for-a-lineblockfile" class="md-nav__link"> |
| How do I suppress errors for a line/block/file? |
| </a> |
| |
| <nav class="md-nav" aria-label="How do I suppress errors for a line/block/file?"> |
| <ul class="md-nav__list"> |
| |
| <li class="md-nav__item"> |
| <a href="#disabling-for-one-specific-line-using-eol-comment" class="md-nav__link"> |
| Disabling for one specific line using EOL comment |
| </a> |
| |
| </li> |
| |
| <li class="md-nav__item"> |
| <a href="#disabling-for-a-block-of-lines-using-block-comments" class="md-nav__link"> |
| Disabling for a block of lines using Block comments |
| </a> |
| |
| </li> |
| |
| <li class="md-nav__item"> |
| <a href="#disabling-for-a-statement-or-an-entire-file-using-suppress" class="md-nav__link"> |
| Disabling for a statement or an entire file using @Suppress |
| </a> |
| |
| </li> |
| |
| </ul> |
| </nav> |
| |
| </li> |
| |
| <li class="md-nav__item"> |
| <a href="#how-do-i-globally-disable-a-rule" class="md-nav__link"> |
| How do I globally disable a rule? |
| </a> |
| |
| </li> |
| |
| <li class="md-nav__item"> |
| <a href="#why-is-editorconfig-property-disabled_rules-deprecated-and-how-do-i-resolve-this" class="md-nav__link"> |
| Why is .editorconfig property disabled_rules deprecated and how do I resolve this? |
| </a> |
| |
| </li> |
| |
| </ul> |
| |
| </nav> |
| |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item md-nav__item--nested"> |
| |
| |
| |
| |
| |
| |
| <input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_6" > |
| |
| |
| |
| <label class="md-nav__link" for="__nav_6" id="__nav_6_label" tabindex="0"> |
| Contributing |
| <span class="md-nav__icon md-icon"></span> |
| </label> |
| |
| <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_6_label" aria-expanded="false"> |
| <label class="md-nav__title" for="__nav_6"> |
| <span class="md-nav__icon md-icon"></span> |
| Contributing |
| </label> |
| <ul class="md-nav__list" data-md-scrollfix> |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item"> |
| <a href="../contributing/overview/" class="md-nav__link"> |
| Overview |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item"> |
| <a href="../contributing/guidelines/" class="md-nav__link"> |
| Guidelines |
| </a> |
| </li> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <li class="md-nav__item"> |
| <a href="../contributing/code-of-conduct/" class="md-nav__link"> |
| Code of conduct |
| </a> |
| </li> |
| |
| |
| |
| |
| </ul> |
| </nav> |
| </li> |
| |
| |
| |
| </ul> |
| </nav> |
| </div> |
| </div> |
| </div> |
| |
| |
| |
| <div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" > |
| <div class="md-sidebar__scrollwrap"> |
| <div class="md-sidebar__inner"> |
| |
| |
| <nav class="md-nav md-nav--secondary" aria-label="Table of contents"> |
| |
| |
| |
| |
| <label class="md-nav__title" for="__toc"> |
| <span class="md-nav__icon md-icon"></span> |
| Table of contents |
| </label> |
| <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix> |
| |
| <li class="md-nav__item"> |
| <a href="#why-should-i-use-ktlint" class="md-nav__link"> |
| Why should I use ktlint? |
| </a> |
| |
| </li> |
| |
| <li class="md-nav__item"> |
| <a href="#can-i-have-my-own-rules-on-top-of-ktlint" class="md-nav__link"> |
| Can I have my own rules on top of ktlint? |
| </a> |
| |
| </li> |
| |
| <li class="md-nav__item"> |
| <a href="#how-do-i-suppress-errors-for-a-lineblockfile" class="md-nav__link"> |
| How do I suppress errors for a line/block/file? |
| </a> |
| |
| <nav class="md-nav" aria-label="How do I suppress errors for a line/block/file?"> |
| <ul class="md-nav__list"> |
| |
| <li class="md-nav__item"> |
| <a href="#disabling-for-one-specific-line-using-eol-comment" class="md-nav__link"> |
| Disabling for one specific line using EOL comment |
| </a> |
| |
| </li> |
| |
| <li class="md-nav__item"> |
| <a href="#disabling-for-a-block-of-lines-using-block-comments" class="md-nav__link"> |
| Disabling for a block of lines using Block comments |
| </a> |
| |
| </li> |
| |
| <li class="md-nav__item"> |
| <a href="#disabling-for-a-statement-or-an-entire-file-using-suppress" class="md-nav__link"> |
| Disabling for a statement or an entire file using @Suppress |
| </a> |
| |
| </li> |
| |
| </ul> |
| </nav> |
| |
| </li> |
| |
| <li class="md-nav__item"> |
| <a href="#how-do-i-globally-disable-a-rule" class="md-nav__link"> |
| How do I globally disable a rule? |
| </a> |
| |
| </li> |
| |
| <li class="md-nav__item"> |
| <a href="#why-is-editorconfig-property-disabled_rules-deprecated-and-how-do-i-resolve-this" class="md-nav__link"> |
| Why is .editorconfig property disabled_rules deprecated and how do I resolve this? |
| </a> |
| |
| </li> |
| |
| </ul> |
| |
| </nav> |
| </div> |
| </div> |
| </div> |
| |
| |
| |
| <div class="md-content" data-md-component="content"> |
| <article class="md-content__inner md-typeset"> |
| |
| |
| |
| |
| |
| |
| |
| <h1>FAQ</h1> |
| |
| <h2 id="why-should-i-use-ktlint">Why should I use ktlint?<a class="headerlink" href="#why-should-i-use-ktlint" title="Permanent link">¶</a></h2> |
| <p>the short answer is <strong>Simplicity</strong>.</p> |
| <p>Spending time on configuration (and maintenance down the road) of hundred-line long style config file(s) is counter-productive. Instead of wasting your energy on something that has no business value - focus on what really matters (not debating whether to use tabs or spaces).</p> |
| <p>By using ktlint you put the importance of code clarity and community conventions over personal preferences. This makes things easier for people reading your code as well as frees you from having to document and explain what style potential contributor(s) have to follow.</p> |
| <p>ktlint is a single binary with both linter & formatter included. All you need is to drop it in (no need to get <a href="https://en.wikipedia.org/wiki/Decision_fatigue">overwhelmed</a> while choosing among <a href="https://checkstyle.sourceforge.net/checks.html">dozens of code style options</a>).</p> |
| <h2 id="can-i-have-my-own-rules-on-top-of-ktlint">Can I have my own rules on top of ktlint?<a class="headerlink" href="#can-i-have-my-own-rules-on-top-of-ktlint" title="Permanent link">¶</a></h2> |
| <p>Absolutely, "no configuration" doesn't mean "no extensibility". You can add your own ruleset(s) to discover potential bugs, check for anti-patterns, etc.</p> |
| <p>See <a href="../extensions/custom-rule-set/">adding a custom rule set</a> for more information.</p> |
| <h2 id="how-do-i-suppress-errors-for-a-lineblockfile">How do I suppress errors for a line/block/file?<a class="headerlink" href="#how-do-i-suppress-errors-for-a-lineblockfile" title="Permanent link">¶</a></h2> |
| <div class="admonition tip"> |
| <p class="admonition-title">Tip</p> |
| <p>Suppressing a <code>ktlint</code> violation is meant primarily as an escape latch for the rare cases when <strong>ktlint</strong> is not able to produce the correct result. Please report any such instances using <a href="https://github.com/pinterest/ktlint/issues">GitHub Issues</a>).</p> |
| </div> |
| <p>To disable a specific rule you'll need the rule identifier which is displayed at the end of the lint error. Note that when the rule id is prefixed with a rule set id like <code>experimental</code>, you will need to use that fully qualified rule id.</p> |
| <p>An error can be suppressed using:</p> |
| <ul> |
| <li>EOL comments</li> |
| <li>Block comments</li> |
| <li>@Suppress annotations</li> |
| </ul> |
| <p>From a consistency perspective seen, it might be best to <strong>not</strong> mix the (EOL/Block) comment style with the annotation style in the same project.</p> |
| <div class="admonition warning"> |
| <p class="admonition-title">Warning</p> |
| <p>Some rules like the <code>indent</code> rule do not (yet) support disabling of the rule per line or block. It can be disabled for an entire file though. </p> |
| </div> |
| <h3 id="disabling-for-one-specific-line-using-eol-comment">Disabling for one specific line using EOL comment<a class="headerlink" href="#disabling-for-one-specific-line-using-eol-comment" title="Permanent link">¶</a></h3> |
| <p>An error for a specific rule on a specific line can be disabled with an EOL comment on that line:</p> |
| <div class="highlight"><pre><span></span><code><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a><span class="k">import</span><span class="w"> </span><span class="nn">package.*</span><span class="w"> </span><span class="c1">// ktlint-disable no-wildcard-imports</span> |
| </code></pre></div> |
| <p>In case lint errors for different rules on the same line need to be ignored, then specify multiple rule ids (separated by a space):</p> |
| <div class="highlight"><pre><span></span><code><a id="__codelineno-1-1" name="__codelineno-1-1" href="#__codelineno-1-1"></a><span class="k">import</span><span class="w"> </span><span class="nn">package.*</span><span class="w"> </span><span class="c1">// ktlint-disable no-wildcard-imports other-rule-id</span> |
| </code></pre></div> |
| <p>In case all lint errors on a line need to be ignored, then do not specify the rule id at all:</p> |
| <div class="highlight"><pre><span></span><code><a id="__codelineno-2-1" name="__codelineno-2-1" href="#__codelineno-2-1"></a><span class="k">import</span><span class="w"> </span><span class="nn">package.*</span><span class="w"> </span><span class="c1">// ktlint-disable</span> |
| </code></pre></div> |
| <h3 id="disabling-for-a-block-of-lines-using-block-comments">Disabling for a block of lines using Block comments<a class="headerlink" href="#disabling-for-a-block-of-lines-using-block-comments" title="Permanent link">¶</a></h3> |
| <p>An error for a specific rule in a block of lines can be disabled with an block comment like:</p> |
| <div class="highlight"><pre><span></span><code><a id="__codelineno-3-1" name="__codelineno-3-1" href="#__codelineno-3-1"></a><span class="cm">/* ktlint-disable no-wildcard-imports */</span> |
| <a id="__codelineno-3-2" name="__codelineno-3-2" href="#__codelineno-3-2"></a><span class="k">import</span><span class="w"> </span><span class="nn">package.a.*</span> |
| <a id="__codelineno-3-3" name="__codelineno-3-3" href="#__codelineno-3-3"></a><span class="k">import</span><span class="w"> </span><span class="nn">package.b.*</span> |
| <a id="__codelineno-3-4" name="__codelineno-3-4" href="#__codelineno-3-4"></a><span class="cm">/* ktlint-enable no-wildcard-imports */</span> |
| </code></pre></div> |
| <p>In case lint errors for different rules in the same block of lines need to be ignored, then specify multiple rule ids (separated by a space):</p> |
| <div class="highlight"><pre><span></span><code><a id="__codelineno-4-1" name="__codelineno-4-1" href="#__codelineno-4-1"></a><span class="cm">/* ktlint-disable no-wildcard-imports other-rule-id */</span> |
| <a id="__codelineno-4-2" name="__codelineno-4-2" href="#__codelineno-4-2"></a><span class="k">import</span><span class="w"> </span><span class="nn">package.a.*</span> |
| <a id="__codelineno-4-3" name="__codelineno-4-3" href="#__codelineno-4-3"></a><span class="k">import</span><span class="w"> </span><span class="nn">package.b.*</span> |
| <a id="__codelineno-4-4" name="__codelineno-4-4" href="#__codelineno-4-4"></a><span class="cm">/* ktlint-enable no-wildcard-imports,other-rule-id */</span> |
| </code></pre></div> |
| <p>Note that the <code>ktlint-enable</code> directive needs to specify the exact same rule-id's and in the same order as the <code>ktlint-disable</code> directive.</p> |
| <p>In case all lint errors in a block of lines needs to be ignored, then do not specify the rule id at all:</p> |
| <div class="highlight"><pre><span></span><code><a id="__codelineno-5-1" name="__codelineno-5-1" href="#__codelineno-5-1"></a><span class="cm">/* ktlint-disable */</span> |
| <a id="__codelineno-5-2" name="__codelineno-5-2" href="#__codelineno-5-2"></a><span class="k">import</span><span class="w"> </span><span class="nn">package.a.*</span> |
| <a id="__codelineno-5-3" name="__codelineno-5-3" href="#__codelineno-5-3"></a><span class="k">import</span><span class="w"> </span><span class="nn">package.b.*</span> |
| <a id="__codelineno-5-4" name="__codelineno-5-4" href="#__codelineno-5-4"></a><span class="cm">/* ktlint-enable */</span> |
| </code></pre></div> |
| <h3 id="disabling-for-a-statement-or-an-entire-file-using-suppress">Disabling for a statement or an entire file using @Suppress<a class="headerlink" href="#disabling-for-a-statement-or-an-entire-file-using-suppress" title="Permanent link">¶</a></h3> |
| <div class="admonition tip"> |
| <p class="admonition-title">Tip</p> |
| <p>As of ktlint version 0.46, it is possible to specify any ktlint rule id via the <code>@Suppress</code> annotation in order to suppress errors found by that rule. Note that some rules like <code>indent</code> still do not support disabling for parts of a file.</p> |
| </div> |
| <p>An error for a specific rule on a specific line can be disabled with a <code>@Suppress</code> annotation:</p> |
| <div class="highlight"><pre><span></span><code><a id="__codelineno-6-1" name="__codelineno-6-1" href="#__codelineno-6-1"></a><span class="nd">@Suppress</span><span class="p">(</span><span class="s">"ktlint:max-line-length"</span><span class="p">,</span><span class="s">"ktlint:experimental:trailing-comma-on-call-site"</span><span class="p">)</span> |
| <a id="__codelineno-6-2" name="__codelineno-6-2" href="#__codelineno-6-2"></a><span class="kd">val</span><span class="w"> </span><span class="nv">foo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">listOf</span><span class="p">(</span> |
| <a id="__codelineno-6-3" name="__codelineno-6-3" href="#__codelineno-6-3"></a><span class="w"> </span><span class="s">"some really looooooooooooooooong string exceeding the max line length"</span><span class="p">,</span> |
| <a id="__codelineno-6-4" name="__codelineno-6-4" href="#__codelineno-6-4"></a><span class="w"> </span><span class="p">)</span> |
| </code></pre></div> |
| <p>Note that when using <code>@Suppress</code> each qualified rule id needs to be prefixed with <code>ktlint:</code>.</p> |
| <p>To suppress the violations of all ktlint rules, use: |
| <div class="highlight"><pre><span></span><code><a id="__codelineno-7-1" name="__codelineno-7-1" href="#__codelineno-7-1"></a><span class="nd">@Suppress</span><span class="p">(</span><span class="s">"ktlint"</span><span class="p">)</span> |
| <a id="__codelineno-7-2" name="__codelineno-7-2" href="#__codelineno-7-2"></a><span class="kd">val</span><span class="w"> </span><span class="nv">foo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"some really looooooooooooooooong string exceeding the max line length"</span> |
| </code></pre></div></p> |
| <p>Like with other <code>@Suppress</code> annotations, it can be placed on targets supported by the annotation. As of this it is possible to disable rules in the entire file with: |
| <div class="highlight"><pre><span></span><code><a id="__codelineno-8-1" name="__codelineno-8-1" href="#__codelineno-8-1"></a><span class="nd">@file</span><span class="p">:</span><span class="n">Suppress</span><span class="p">(</span><span class="s">"ktlint"</span><span class="p">)</span><span class="w"> </span><span class="c1">// Suppressing all rules for the entire file</span> |
| <a id="__codelineno-8-2" name="__codelineno-8-2" href="#__codelineno-8-2"></a><span class="c1">// or</span> |
| <a id="__codelineno-8-3" name="__codelineno-8-3" href="#__codelineno-8-3"></a><span class="nd">@file</span><span class="p">:</span><span class="n">Suppress</span><span class="p">(</span><span class="s">"ktlint:max-line-length"</span><span class="p">,</span><span class="s">"ktlint:experimental:trailing-comma"</span><span class="p">)</span><span class="w"> </span><span class="c1">// Suppressing specific rules for the entire file</span> |
| </code></pre></div></p> |
| <h2 id="how-do-i-globally-disable-a-rule">How do I globally disable a rule?<a class="headerlink" href="#how-do-i-globally-disable-a-rule" title="Permanent link">¶</a></h2> |
| <p>With <a href="../rules/configuration-ktlint#disabled-rules"><code>.editorConfig</code> property <code>disabled_rules</code></a> a rule can be disabled globally.</p> |
| <p>You may also pass a list of disabled rules via the <code>--disabled_rules</code> command line flag. It has the same syntax as the EditorConfig property.</p> |
| <h2 id="why-is-editorconfig-property-disabled_rules-deprecated-and-how-do-i-resolve-this">Why is <code>.editorconfig</code> property <code>disabled_rules</code> deprecated and how do I resolve this?<a class="headerlink" href="#why-is-editorconfig-property-disabled_rules-deprecated-and-how-do-i-resolve-this" title="Permanent link">¶</a></h2> |
| <p>The <code>.editorconfig</code> properties <code>disabled_rules</code> and <code>ktlint_disbaled_rules</code> are deprecated as of KtLint version <code>0.48</code> and are marked for removal in version <code>0.49</code>. Those properties contain a comma separated list of rules which are disabled. Using a comma separated list of values has some disadvantages.</p> |
| <p>A big disadvantage is that it is not possible to override the property partially in an <code>.editorconfig</code> file in a subpackage. Another disadvantage is that it is not possible to express explicitly that a rule is enabled. Lastly, (qualified) rule ids can be 20 characters or longer, which makes a list with multiple entries hard to read.</p> |
| <p><em>Root <code>.editorconfig</code></em> |
| <div class="highlight"><pre><span></span><code><a id="__codelineno-9-1" name="__codelineno-9-1" href="#__codelineno-9-1"></a>root = true |
| <a id="__codelineno-9-2" name="__codelineno-9-2" href="#__codelineno-9-2"></a> |
| <a id="__codelineno-9-3" name="__codelineno-9-3" href="#__codelineno-9-3"></a>[*.kt] |
| <a id="__codelineno-9-4" name="__codelineno-9-4" href="#__codelineno-9-4"></a>disabled_rules=rule-1,rule-2,rule-3 |
| </code></pre></div> |
| This <code>.editorconfig</code> defines that all rules except <code>rule-1</code>, <code>rule-2</code> and <code>rule-3</code> should be run in all packages. Suppose that we want to enable <code>rule-1</code> but disable <code>rule-4</code> in certain subpackage, then we would need to define an <code>.editorconfig</code> file like below:</p> |
| <p><em>Secondary <code>.editorconfig</code></em> |
| <div class="highlight"><pre><span></span><code><a id="__codelineno-10-1" name="__codelineno-10-1" href="#__codelineno-10-1"></a>[*.kt] |
| <a id="__codelineno-10-2" name="__codelineno-10-2" href="#__codelineno-10-2"></a>disabled_rules=rule-2,rule-4,rule-3 |
| </code></pre></div> |
| Disabling another rule in the root <code>.editorconfig</code> file, does not have effect on this subpackage as long as that rule has not been added to the <code>.editorconfig</code> file in the subpackage. </p> |
| <p>Starting with KtLint <code>0.48</code> entire rule sets and individual rules can be disabled / enabled with a separate property per rule (set). </p> |
| <p>All rules in a rule set can be enabled or disabled with a rule set property. The name of the rule set property consists of the <code>ktlint_</code> prefix followed by the rule set id. Examples: |
| <div class="highlight"><pre><span></span><code><a id="__codelineno-11-1" name="__codelineno-11-1" href="#__codelineno-11-1"></a>ktlint_standard = disabled # Disable all rules from the `standard` rule set provided by KtLint |
| <a id="__codelineno-11-2" name="__codelineno-11-2" href="#__codelineno-11-2"></a>ktlint_experimental = enabled # Enable all rules from the `experimental` rule set provided by KtLint |
| <a id="__codelineno-11-3" name="__codelineno-11-3" href="#__codelineno-11-3"></a>ktlint_your-custom-rule-set_custom-rule = enabled # Enable all rules in the `custom-rule-set` rule set (not provided by KtLint) |
| </code></pre></div></p> |
| <div class="admonition note"> |
| <p class="admonition-title">Note</p> |
| <p>All rules from the <code>standard</code> rule set are <em>enabled</em> by default and can optionally be disabled in the <code>.editorconfig</code>. All rules from the <code>experimental</code> and <em>custom</em> rule sets are <em>disabled</em> by default and can optionally be enabled in the <code>.editorconfig</code>.</p> |
| </div> |
| <p>An individual property can be enabled or disabled with a rule property. The name of the rule property consists of the <code>ktlint_</code> prefix followed by the rule set id followed by a <code>_</code> and the rule id. Examples: |
| <div class="highlight"><pre><span></span><code><a id="__codelineno-12-1" name="__codelineno-12-1" href="#__codelineno-12-1"></a>ktlint_standard_final-newline = disabled # Disables the `final-newline` rule in the `standard` rule set provided by KtLint |
| <a id="__codelineno-12-2" name="__codelineno-12-2" href="#__codelineno-12-2"></a>ktlint_experimental_type-argument-list-spacing = enabled # Enables the `type-argument-list-spacing` rule in the `experimental` rule set provided by KtLint |
| <a id="__codelineno-12-3" name="__codelineno-12-3" href="#__codelineno-12-3"></a>ktlint_custom-rule-set_custom-rule = disabled # Disables the `custom-rule` rule in the `custom-rule-set` rule set (not provided by KtLint) |
| </code></pre></div></p> |
| <div class="admonition note"> |
| <p class="admonition-title">Note</p> |
| <p>The <em>rule</em> properties are applied after applying the <em>rule set</em> properties and take precedence. So if a rule set is disabled but a specific rule of that rule set is enabled, then the rule will be executed. </p> |
| </div> |
| |
| |
| |
| |
| |
| |
| </article> |
| </div> |
| |
| |
| </div> |
| |
| </main> |
| |
| <footer class="md-footer"> |
| |
| <div class="md-footer-meta md-typeset"> |
| <div class="md-footer-meta__inner md-grid"> |
| <div class="md-copyright"> |
| |
| |
| Made with |
| <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener"> |
| Material for MkDocs |
| </a> |
| |
| </div> |
| |
| </div> |
| </div> |
| </footer> |
| |
| </div> |
| <div class="md-dialog" data-md-component="dialog"> |
| <div class="md-dialog__inner md-typeset"></div> |
| </div> |
| |
| <script id="__config" type="application/json">{"base": "..", "features": ["navigation.tabs", "navigation.tabs.sticky", "navigation.sections", "navigation.expand", "search.suggest", "search.share"], "search": "../assets/javascripts/workers/search.208ed371.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": {"provider": "mike"}}</script> |
| |
| |
| <script src="../assets/javascripts/bundle.51198bba.min.js"></script> |
| |
| |
| </body> |
| </html> |