private void processFiles() throws IOException { for (File file : files) { String code = readFileContents(file); ProblemHandler handler = new SysoutProblemHandler(file.getAbsolutePath()); jshint.check(code, handler); } }
private void loadJSHint() { jshint = new JSHint(); try { if (library != null) { FileInputStream inputStream = new FileInputStream(library); try { jshint.load(inputStream); } finally { inputStream.close(); } } else { jshint.load(); } } catch (Exception exception) { String message = "Failed to load JSHint library: " + exception.getMessage(); throw new IllegalArgumentException(message); } }
private static void validateFile(File file) throws IllegalArgumentException { if (!file.isFile()) { throw new IllegalArgumentException("File does not exist"); } if (!file.canRead()) { throw new IllegalArgumentException("File is not readable"); } try { FileInputStream inputStream = new FileInputStream(file); try { JSHint jsHint = new JSHint(); jsHint.load(inputStream); } finally { inputStream.close(); } } catch (Exception exception) { throw new IllegalArgumentException("File is not a valid JSHint library", exception); } }
private void createCustomJSHintArea(Composite parent) { defaultLibRadio = new Button(parent, SWT.RADIO); String version = JSHint.getDefaultLibraryVersion(); defaultLibRadio.setText("Use the &built-in JSHint library (version " + version + ")"); gridData(defaultLibRadio).fillHorizontal().span(3, 1); customLibRadio = new Button(parent, SWT.RADIO); customLibRadio.setText("Provide a &custom JSHint library file"); gridData(customLibRadio).fillHorizontal().span(3, 1); customLibRadio.addListener( SWT.Selection, new Listener() { public void handleEvent(Event event) { preferences.setUseCustomLib(customLibRadio.getSelection()); validate(); updateControlsEnabled(); } }); customLibPathText = new Text(parent, SWT.BORDER); gridData(customLibPathText).fillHorizontal().span(2, 1).indent(25, 0); customLibPathText.addListener( SWT.Modify, new Listener() { public void handleEvent(Event event) { preferences.setCustomLibPath(customLibPathText.getText()); validate(); } }); customLibPathButton = new Button(parent, SWT.PUSH); customLibPathButton.setText("Select"); customLibPathButton.addListener( SWT.Selection, new Listener() { public void handleEvent(Event event) { selectFile(); } }); Text customLibPathLabelText = new Text(parent, SWT.READ_ONLY | SWT.WRAP); customLibPathLabelText.setText("This file is usually named 'jshint.js'."); customLibPathLabelText.setBackground(parent.getBackground()); gridData(customLibPathLabelText).fillHorizontal().span(3, 1).indent(25, 1); }
private void configureJSHint() { JsonObject configuration = new JsonObject(); configuration.add("undef", true); jshint.configure(configuration); }