tslint says calls to console.log are not allowed - How do I allow this?











up vote
27
down vote

favorite
3












I just started using create-react-app with typescript



create-react-app my-app --scripts-version=react-scripts-ts


and the default tslint.json configuration does not allow console.log().



How can I (for now) enable console.log?



The docs for this are at https://palantir.github.io/tslint/rules/no-console/. But they don't say where to put this line:



    "no-console": [true, "log", "error"]


I searched and found this tslint.json configuration file syntax, so I tried this:



"rules": {
"no-console": [true, "warning"]
}


In an attempt to get log messages that would just be warnings.
But that didn't work.



I've commented out the few console.log() lines I have but will want to be able to do this in the future.










share|improve this question




























    up vote
    27
    down vote

    favorite
    3












    I just started using create-react-app with typescript



    create-react-app my-app --scripts-version=react-scripts-ts


    and the default tslint.json configuration does not allow console.log().



    How can I (for now) enable console.log?



    The docs for this are at https://palantir.github.io/tslint/rules/no-console/. But they don't say where to put this line:



        "no-console": [true, "log", "error"]


    I searched and found this tslint.json configuration file syntax, so I tried this:



    "rules": {
    "no-console": [true, "warning"]
    }


    In an attempt to get log messages that would just be warnings.
    But that didn't work.



    I've commented out the few console.log() lines I have but will want to be able to do this in the future.










    share|improve this question


























      up vote
      27
      down vote

      favorite
      3









      up vote
      27
      down vote

      favorite
      3






      3





      I just started using create-react-app with typescript



      create-react-app my-app --scripts-version=react-scripts-ts


      and the default tslint.json configuration does not allow console.log().



      How can I (for now) enable console.log?



      The docs for this are at https://palantir.github.io/tslint/rules/no-console/. But they don't say where to put this line:



          "no-console": [true, "log", "error"]


      I searched and found this tslint.json configuration file syntax, so I tried this:



      "rules": {
      "no-console": [true, "warning"]
      }


      In an attempt to get log messages that would just be warnings.
      But that didn't work.



      I've commented out the few console.log() lines I have but will want to be able to do this in the future.










      share|improve this question















      I just started using create-react-app with typescript



      create-react-app my-app --scripts-version=react-scripts-ts


      and the default tslint.json configuration does not allow console.log().



      How can I (for now) enable console.log?



      The docs for this are at https://palantir.github.io/tslint/rules/no-console/. But they don't say where to put this line:



          "no-console": [true, "log", "error"]


      I searched and found this tslint.json configuration file syntax, so I tried this:



      "rules": {
      "no-console": [true, "warning"]
      }


      In an attempt to get log messages that would just be warnings.
      But that didn't work.



      I've commented out the few console.log() lines I have but will want to be able to do this in the future.







      reactjs typescript create-react-app tslint






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 3 at 12:13









      Lee Brindley

      3,17111944




      3,17111944










      asked Apr 23 at 21:54









      PatS

      6612921




      6612921
























          3 Answers
          3






          active

          oldest

          votes

















          up vote
          62
          down vote



          accepted










          Add // tslint:disable-next-line:no-console in the line right before your calls to console.log to prevent the error message only once.



          If you want to disable the rule entirely add the following to your tslint.json (most likely in your root folder):



          {
          "rules": {
          "no-console": false
          }
          }





          share|improve this answer



















          • 4




            I'm not sure what happened but now "no-console": false is not working for me. I've found a work around is to put // tslint:disable:no-console at the top of the file.
            – PatS
            Apr 26 at 17:07








          • 5




            "no-console": false works for me, but I have to restart "npm start" for it to take effect.
            – jlb
            May 21 at 19:56






          • 2




            "no-console": false doesn't work for me, even with npm run start.
            – Eric Fulmer
            May 22 at 18:16








          • 13




            @EricFulmer put that in the "jsRules" node. "jsRules": { "no-console": false },
            – billb
            May 25 at 16:26










          • @billb That works -- thank you!
            – Eric Fulmer
            May 25 at 23:06


















          up vote
          11
          down vote













          For those of you coming here with a mixed codebase of javascript and typescript.



          You may need to define the 'no-console' option in jsRules, jslints rules object for javascript files, i.e. there are separate rules objects for javascript and typescript.



          //tslint.json



          {
          "extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"], //Example...
          "rules": {
          "no-console": false //Disable for typescript
          },
          "jsRules": {
          "no-console": false //Disable for javascript
          }
          }





          share|improve this answer






























            up vote
            2
            down vote













            According to the docs: https://eslint.org/docs/user-guide/getting-started#configuration




            • "off" or 0 - turn the rule off

            • "warn" or 1 - turn the rule on as a warning (doesn’t affect exit code)

            • "error" or 2 - turn the rule on as an error (exit code will be 1)


            By the way, your correct setup would be



            {
            "rules": {
            "no-console": false
            }
            }





            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49990513%2ftslint-says-calls-to-console-log-are-not-allowed-how-do-i-allow-this%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              62
              down vote



              accepted










              Add // tslint:disable-next-line:no-console in the line right before your calls to console.log to prevent the error message only once.



              If you want to disable the rule entirely add the following to your tslint.json (most likely in your root folder):



              {
              "rules": {
              "no-console": false
              }
              }





              share|improve this answer



















              • 4




                I'm not sure what happened but now "no-console": false is not working for me. I've found a work around is to put // tslint:disable:no-console at the top of the file.
                – PatS
                Apr 26 at 17:07








              • 5




                "no-console": false works for me, but I have to restart "npm start" for it to take effect.
                – jlb
                May 21 at 19:56






              • 2




                "no-console": false doesn't work for me, even with npm run start.
                – Eric Fulmer
                May 22 at 18:16








              • 13




                @EricFulmer put that in the "jsRules" node. "jsRules": { "no-console": false },
                – billb
                May 25 at 16:26










              • @billb That works -- thank you!
                – Eric Fulmer
                May 25 at 23:06















              up vote
              62
              down vote



              accepted










              Add // tslint:disable-next-line:no-console in the line right before your calls to console.log to prevent the error message only once.



              If you want to disable the rule entirely add the following to your tslint.json (most likely in your root folder):



              {
              "rules": {
              "no-console": false
              }
              }





              share|improve this answer



















              • 4




                I'm not sure what happened but now "no-console": false is not working for me. I've found a work around is to put // tslint:disable:no-console at the top of the file.
                – PatS
                Apr 26 at 17:07








              • 5




                "no-console": false works for me, but I have to restart "npm start" for it to take effect.
                – jlb
                May 21 at 19:56






              • 2




                "no-console": false doesn't work for me, even with npm run start.
                – Eric Fulmer
                May 22 at 18:16








              • 13




                @EricFulmer put that in the "jsRules" node. "jsRules": { "no-console": false },
                – billb
                May 25 at 16:26










              • @billb That works -- thank you!
                – Eric Fulmer
                May 25 at 23:06













              up vote
              62
              down vote



              accepted







              up vote
              62
              down vote



              accepted






              Add // tslint:disable-next-line:no-console in the line right before your calls to console.log to prevent the error message only once.



              If you want to disable the rule entirely add the following to your tslint.json (most likely in your root folder):



              {
              "rules": {
              "no-console": false
              }
              }





              share|improve this answer














              Add // tslint:disable-next-line:no-console in the line right before your calls to console.log to prevent the error message only once.



              If you want to disable the rule entirely add the following to your tslint.json (most likely in your root folder):



              {
              "rules": {
              "no-console": false
              }
              }






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Apr 25 at 22:00

























              answered Apr 23 at 22:02









              Christian Ivicevic

              3,16652549




              3,16652549








              • 4




                I'm not sure what happened but now "no-console": false is not working for me. I've found a work around is to put // tslint:disable:no-console at the top of the file.
                – PatS
                Apr 26 at 17:07








              • 5




                "no-console": false works for me, but I have to restart "npm start" for it to take effect.
                – jlb
                May 21 at 19:56






              • 2




                "no-console": false doesn't work for me, even with npm run start.
                – Eric Fulmer
                May 22 at 18:16








              • 13




                @EricFulmer put that in the "jsRules" node. "jsRules": { "no-console": false },
                – billb
                May 25 at 16:26










              • @billb That works -- thank you!
                – Eric Fulmer
                May 25 at 23:06














              • 4




                I'm not sure what happened but now "no-console": false is not working for me. I've found a work around is to put // tslint:disable:no-console at the top of the file.
                – PatS
                Apr 26 at 17:07








              • 5




                "no-console": false works for me, but I have to restart "npm start" for it to take effect.
                – jlb
                May 21 at 19:56






              • 2




                "no-console": false doesn't work for me, even with npm run start.
                – Eric Fulmer
                May 22 at 18:16








              • 13




                @EricFulmer put that in the "jsRules" node. "jsRules": { "no-console": false },
                – billb
                May 25 at 16:26










              • @billb That works -- thank you!
                – Eric Fulmer
                May 25 at 23:06








              4




              4




              I'm not sure what happened but now "no-console": false is not working for me. I've found a work around is to put // tslint:disable:no-console at the top of the file.
              – PatS
              Apr 26 at 17:07






              I'm not sure what happened but now "no-console": false is not working for me. I've found a work around is to put // tslint:disable:no-console at the top of the file.
              – PatS
              Apr 26 at 17:07






              5




              5




              "no-console": false works for me, but I have to restart "npm start" for it to take effect.
              – jlb
              May 21 at 19:56




              "no-console": false works for me, but I have to restart "npm start" for it to take effect.
              – jlb
              May 21 at 19:56




              2




              2




              "no-console": false doesn't work for me, even with npm run start.
              – Eric Fulmer
              May 22 at 18:16






              "no-console": false doesn't work for me, even with npm run start.
              – Eric Fulmer
              May 22 at 18:16






              13




              13




              @EricFulmer put that in the "jsRules" node. "jsRules": { "no-console": false },
              – billb
              May 25 at 16:26




              @EricFulmer put that in the "jsRules" node. "jsRules": { "no-console": false },
              – billb
              May 25 at 16:26












              @billb That works -- thank you!
              – Eric Fulmer
              May 25 at 23:06




              @billb That works -- thank you!
              – Eric Fulmer
              May 25 at 23:06












              up vote
              11
              down vote













              For those of you coming here with a mixed codebase of javascript and typescript.



              You may need to define the 'no-console' option in jsRules, jslints rules object for javascript files, i.e. there are separate rules objects for javascript and typescript.



              //tslint.json



              {
              "extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"], //Example...
              "rules": {
              "no-console": false //Disable for typescript
              },
              "jsRules": {
              "no-console": false //Disable for javascript
              }
              }





              share|improve this answer



























                up vote
                11
                down vote













                For those of you coming here with a mixed codebase of javascript and typescript.



                You may need to define the 'no-console' option in jsRules, jslints rules object for javascript files, i.e. there are separate rules objects for javascript and typescript.



                //tslint.json



                {
                "extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"], //Example...
                "rules": {
                "no-console": false //Disable for typescript
                },
                "jsRules": {
                "no-console": false //Disable for javascript
                }
                }





                share|improve this answer

























                  up vote
                  11
                  down vote










                  up vote
                  11
                  down vote









                  For those of you coming here with a mixed codebase of javascript and typescript.



                  You may need to define the 'no-console' option in jsRules, jslints rules object for javascript files, i.e. there are separate rules objects for javascript and typescript.



                  //tslint.json



                  {
                  "extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"], //Example...
                  "rules": {
                  "no-console": false //Disable for typescript
                  },
                  "jsRules": {
                  "no-console": false //Disable for javascript
                  }
                  }





                  share|improve this answer














                  For those of you coming here with a mixed codebase of javascript and typescript.



                  You may need to define the 'no-console' option in jsRules, jslints rules object for javascript files, i.e. there are separate rules objects for javascript and typescript.



                  //tslint.json



                  {
                  "extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"], //Example...
                  "rules": {
                  "no-console": false //Disable for typescript
                  },
                  "jsRules": {
                  "no-console": false //Disable for javascript
                  }
                  }






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 11 at 22:20

























                  answered Sep 3 at 12:12









                  Lee Brindley

                  3,17111944




                  3,17111944






















                      up vote
                      2
                      down vote













                      According to the docs: https://eslint.org/docs/user-guide/getting-started#configuration




                      • "off" or 0 - turn the rule off

                      • "warn" or 1 - turn the rule on as a warning (doesn’t affect exit code)

                      • "error" or 2 - turn the rule on as an error (exit code will be 1)


                      By the way, your correct setup would be



                      {
                      "rules": {
                      "no-console": false
                      }
                      }





                      share|improve this answer

























                        up vote
                        2
                        down vote













                        According to the docs: https://eslint.org/docs/user-guide/getting-started#configuration




                        • "off" or 0 - turn the rule off

                        • "warn" or 1 - turn the rule on as a warning (doesn’t affect exit code)

                        • "error" or 2 - turn the rule on as an error (exit code will be 1)


                        By the way, your correct setup would be



                        {
                        "rules": {
                        "no-console": false
                        }
                        }





                        share|improve this answer























                          up vote
                          2
                          down vote










                          up vote
                          2
                          down vote









                          According to the docs: https://eslint.org/docs/user-guide/getting-started#configuration




                          • "off" or 0 - turn the rule off

                          • "warn" or 1 - turn the rule on as a warning (doesn’t affect exit code)

                          • "error" or 2 - turn the rule on as an error (exit code will be 1)


                          By the way, your correct setup would be



                          {
                          "rules": {
                          "no-console": false
                          }
                          }





                          share|improve this answer












                          According to the docs: https://eslint.org/docs/user-guide/getting-started#configuration




                          • "off" or 0 - turn the rule off

                          • "warn" or 1 - turn the rule on as a warning (doesn’t affect exit code)

                          • "error" or 2 - turn the rule on as an error (exit code will be 1)


                          By the way, your correct setup would be



                          {
                          "rules": {
                          "no-console": false
                          }
                          }






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jun 4 at 15:27









                          loretoparisi

                          7,54554770




                          7,54554770






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f49990513%2ftslint-says-calls-to-console-log-are-not-allowed-how-do-i-allow-this%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Xamarin.iOS Cant Deploy on Iphone

                              Glorious Revolution

                              Dulmage-Mendelsohn matrix decomposition in Python