Pregunta

Does anyone know of anything like pylint or pychecker for notepad++? Or perhaps how to use pylint in notepad++.

¿Fue útil?

Solución

If you install the Python Script plugin, then you can add a new script with the following lines to get pretty good results:

console.show()
console.clear()
console.run('cmd.exe /c '
            + 'C:\\Python26\\Scripts\\pylint.bat --reports=n -f parseable '
            + '"%s"' % notepad.getCurrentFilename())

The output will include hyperlinks to the lines with the errors/warnings (if the filenames don't have spaces in them...)

Otros consejos

The option "-f parseable" is deprecated in the current version of Pylint.

The current equivalent alternative is:

console.run('cmd.exe /c '
        + 'C:\\Python26\\Scripts\\pylint.bat --reports=n '
        + '--msg-template="%s" %s' 
        % ( '{path}:{line}: {msg_id}({symbol}), {obj} {msg}', notepad.getCurrentFilename()))

Note: python path can be different e.g. C:\\Python27.

Note2: double quotes in --msg-template="..." are important

None of the other answers worked for me, but this does:

  1. Install PyLint using C:\Python34\Scripts\pip.exe install pylint

  2. Install NppExec via the Plugin Manager, press F6, and save this script as "PyLint 3.4":

    NPP_SAVE
    cd "$(FULL_CURRENT_PATH)"
    //env_set PYTHONIOENCODING=utf-16-le
    env_set PYTHONIOENCODING=utf-8
    C:\Python34\Scripts\pylint.exe --reports=n -f parseable "$(FULL_CURRENT_PATH)"
    

Sample output:

Process started >>>
************* Module pylint2
pylint2.py:3: [C0330(bad-continuation), ] Wrong continued indentation (add 4 spaces).
        + 'C:\\Python26\\Scripts\\pylint.bat --reports=n '
        ^   |
pylint2.py:4: [C0330(bad-continuation), ] Wrong continued indentation (add 4 spaces).
        + '--msg-template="%s" %s' 
        ^   |
pylint2.py:4: [C0303(trailing-whitespace), ] Trailing whitespace
pylint2.py:5: [C0330(bad-continuation), ] Wrong continued indentation (add 4 spaces).
        % ( '{path}:{line}: {msg_id}({symbol}), {obj} {msg}', notepad.getCurrentFilename()))
        ^   |
pylint2.py:5: [C0326(bad-whitespace), ] No space allowed after bracket
        % ( '{path}:{line}: {msg_id}({symbol}), {obj} {msg}', notepad.getCurrentFilename()))
          ^
pylint2.py:6: [C0304(missing-final-newline), ] Final newline missing
pylint2.py:1: [C0111(missing-docstring), ] Missing module docstring
pylint2.py:2: [E0602(undefined-variable), ] Undefined variable 'console'
pylint2.py:5: [E0602(undefined-variable), ] Undefined variable 'notepad'
No config file found, using default configuration
<<< Process finished. (Exit code 18)

You can link those paths using NppExec's Console Output Filters. Press Shift+F6 and enable this filter with Red set to FF:

%FILE%:%LINE%:*

Then double clicking a red line focuses the specified location in the editor.

You could install PyLint using C:\Python34\Scripts>pip install pylint and use it via Notepad++'s Run... command (F5):

C:\Python34\Scripts\pylint.bat "$(FULL_CURRENT_PATH)"

You should use the Executable instead of the Batch if you want to use Pylint within NotePad++.

Go to the Configuration from Python Script and create a new .py File to run Pylint from that. (i called my file npphelper.py)
(Add that npphelper.py to Menu-items and Toolbar-icons, then you can execute it by pressing a Button.)

This will run Pylint into Notepad++, i splitted the Command into 2 Parts:

pyLint = 'C:\\PROGRA~1\\Python35\\Scripts\\pylint.exe --reports=n'
console.show()
console.clear()
console.run('%s "%s"' % (pyLint, notepad.getCurrentFilename()))
  1. Path to pylint.exe (i used a Shortname instead of Doublequotes)
  2. The File you want to check with Pylint (actualy returns the Path from active Tab)

(You have to change the Paths so that it fits to your Installation...)

All you have to do now is saving this npphelper.py, open the Tab with your Project-File and run the npphelper.py you created for pylint. (e.g. via button)


If you don't want to use the default Configuration then generate a pylintrc Template (save them where you want). I've done it via CMD with the following Command:

pylint.exe --generate-rcfile>>myfilename.pylintrc

Then you need to change some lines into the npphelper.py:

rcfile = 'C:\\PROGRA~1\\Python35\\Scripts\\myrcfile.pylintrc'
pyLint = 'C:\\PROGRA~1\\Python35\\Scripts\\pylint.exe --reports=n --rcfile="%s"' % rcfile
console.show()
console.clear()
console.run('%s "%s"' % (pyLint, notepad.getCurrentFilename()))

I've installed Python Script 1.0.8.0 with all the Extras using the .msi File here.
(Using the PluginManager in Notepad++ gives you version 1.0.6.0 instead of 1.0.8.0)

I use Windows 7 with Notepad++ 6.9.1, Python 3.5.1 and Pylint 1.5.5.
(i installed pylint via CMD -> "pip install pylint" and updated it.)


Some more usefull Links:

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top