Skip to content

prettier and lint #611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: LLVM
ColumnLimit: 120
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/devcontainers/javascript-node:22

RUN apt-get update
RUN apt-get install -y openjdk-17-jdk gdb
RUN apt-get install -y openjdk-17-jdk gdb clang-format
6 changes: 6 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@ jobs:
node-version: ${{ matrix.nodeVersion }}
- name: npm ci
run: npm ci
- name: npm run format-cpp
run: npm run format-cpp
- name: npm run format
run: npm run format
- name: npm run lint
run: npm run lint
- name: Unit test
run: npm test
6 changes: 6 additions & 0 deletions .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ jobs:
node-version: ${{ matrix.nodeVersion }}
- name: npm ci
run: npm ci
- name: npm run format-cpp
run: npm run format-cpp
- name: npm run format
run: npm run format
- name: npm run lint
run: npm run lint
- name: Unit test
run: npm test
23 changes: 23 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**/*.cpp
**/*.h
**/*.ppt
**/*.jar
**/*.class
**/*.java
**/*.sh
**/*.html
**/*.json
**/*.png
**/*.md
**/*.rule
**/*.rules
**/*.gyp
**/*.yml
**/Dockerfile
.clang-format
.prettierrc
.prettierignore
.npmignore
.gitignore
.gitattributes
LICENSE
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"parser": "typescript",
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false,
"printWidth": 120,
"endOfLine": "lf"
}
25 changes: 25 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import js from "@eslint/js";
import globals from "globals";
import { defineConfig } from "eslint/config";

export default defineConfig([
{
files: ["**/*.{js,mjs,cjs}"],
plugins: { js },
extends: ["js/recommended"],
languageOptions: { globals: globals.node },
rules: {
"no-var": ["error"],
curly: ["error"],
"no-unused-vars": [
"warn",
{
varsIgnorePattern: "^_",
argsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
},
],
},
},
]);
84 changes: 49 additions & 35 deletions examples/lucene/example.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,74 @@
#!/usr/bin/env node

var java = require("../../");
const java = require("../../");
java.classpath.push("./lucene-lib/lucene-core-7.4.0.jar");
java.classpath.push("./lucene-lib/lucene-analyzers-common-7.4.0.jar");
java.classpath.push("./lucene-lib/lucene-queryparser-7.4.0.jar");

const idx = java.newInstanceSync("org.apache.lucene.store.RAMDirectory");
const analyzer = java.newInstanceSync("org.apache.lucene.analysis.standard.StandardAnalyzer");
const writerConfig = java.newInstanceSync("org.apache.lucene.index.IndexWriterConfig", analyzer);
const writer = java.newInstanceSync("org.apache.lucene.index.IndexWriter", idx, writerConfig);
const queryParser = java.newInstanceSync("org.apache.lucene.queryparser.classic.QueryParser", "content", analyzer);

var idx = java.newInstanceSync("org.apache.lucene.store.RAMDirectory");
var analyzer = java.newInstanceSync("org.apache.lucene.analysis.standard.StandardAnalyzer");
var writerConfig = java.newInstanceSync("org.apache.lucene.index.IndexWriterConfig", analyzer);
var writer = java.newInstanceSync("org.apache.lucene.index.IndexWriter", idx, writerConfig);
var queryParser = java.newInstanceSync("org.apache.lucene.queryparser.classic.QueryParser", "content", analyzer);

writer.addDocumentSync(createDocument("Theodore Roosevelt",
"It behooves every man to remember that the work of the " +
"critic, is of altogether secondary importance, and that, " +
"in the end, progress is accomplished by the man who does " +
"things."));
writer.addDocumentSync(createDocument("Friedrich Hayek",
"The case for individual freedom rests largely on the " +
"recognition of the inevitable and universal ignorance " +
"of all of us concerning a great many of the factors on " +
"which the achievements of our ends and welfare depend."));
writer.addDocumentSync(createDocument("Ayn Rand",
"There is nothing to take a man's freedom away from " +
"him, save other men. To be free, a man must be free " +
"of his brothers."));
writer.addDocumentSync(createDocument("Mohandas Gandhi",
"Freedom is not worth having if it does not connote " +
"freedom to err."));
writer.addDocumentSync(
createDocument(
"Theodore Roosevelt",
"It behooves every man to remember that the work of the " +
"critic, is of altogether secondary importance, and that, " +
"in the end, progress is accomplished by the man who does " +
"things."
)
);
writer.addDocumentSync(
createDocument(
"Friedrich Hayek",
"The case for individual freedom rests largely on the " +
"recognition of the inevitable and universal ignorance " +
"of all of us concerning a great many of the factors on " +
"which the achievements of our ends and welfare depend."
)
);
writer.addDocumentSync(
createDocument(
"Ayn Rand",
"There is nothing to take a man's freedom away from " +
"him, save other men. To be free, a man must be free " +
"of his brothers."
)
);
writer.addDocumentSync(
createDocument("Mohandas Gandhi", "Freedom is not worth having if it does not connote " + "freedom to err.")
);

writer.closeSync();

var searcher = java.newInstanceSync("org.apache.lucene.search.IndexSearcher", java.callStaticMethodSync("org.apache.lucene.index.DirectoryReader", "open", idx));
const searcher = java.newInstanceSync(
"org.apache.lucene.search.IndexSearcher",
java.callStaticMethodSync("org.apache.lucene.index.DirectoryReader", "open", idx)
);

search(searcher, "freedom");
search(searcher, "free");
search(searcher, "progress or achievements");

function createDocument(title, content) {
var fieldStoreYes = java.callStaticMethodSync("org.apache.lucene.document.Field$Store", "valueOf", "YES");
var doc = java.newInstanceSync("org.apache.lucene.document.Document");
const fieldStoreYes = java.callStaticMethodSync("org.apache.lucene.document.Field$Store", "valueOf", "YES");
const doc = java.newInstanceSync("org.apache.lucene.document.Document");
doc.addSync(java.newInstanceSync("org.apache.lucene.document.TextField", "title", title, fieldStoreYes));
doc.addSync(java.newInstanceSync("org.apache.lucene.document.TextField", "content", content, fieldStoreYes));
return doc;
}

function search(searcher, queryString) {
var query = queryParser.parseSync(queryString);
var topDocs = searcher.searchSync(query, 10);

console.log("Found " + topDocs.totalHits + " hits for query \"" + queryString + "\".");
var scoreDocs = topDocs.scoreDocs;
for(var i=0; i<topDocs.scoreDocs.length; i++) {
var docId = scoreDocs[i].doc;
var doc = searcher.docSync(docId);
const query = queryParser.parseSync(queryString);
const topDocs = searcher.searchSync(query, 10);

console.log("Found " + topDocs.totalHits + ' hits for query "' + queryString + '".');
const scoreDocs = topDocs.scoreDocs;
for (let i = 0; i < topDocs.scoreDocs.length; i++) {
const docId = scoreDocs[i].doc;
const doc = searcher.docSync(docId);
console.log(" " + (i + 1) + ". " + doc.getSync("title"));
}
}
8 changes: 3 additions & 5 deletions examples/mixJavaAndNode/runMyClass.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#!/usr/bin/env node

var java = require("../../");
const java = require("../../");
java.classpath.push("./src");

var MyClass = java.import("com.nearinfinity.nodeJava.MyClass");
const MyClass = java.import("com.nearinfinity.nodeJava.MyClass");

var result = MyClass.addNumbersSync(1, 2);
const result = MyClass.addNumbersSync(1, 2);
console.log(result);


6 changes: 4 additions & 2 deletions findJavaHome.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require('find-java-home')(function(err, home){
require("find-java-home")(function (err, home) {
if (err || !home) {
if (!err) err = Error('Unable to determine Java home location');
if (!err) {
err = Error("Unable to determine Java home location");
}
process.exit(1);
}
process.stdout.write(home);
Expand Down
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

module.exports = require("./lib/nodeJavaBridge");
Loading