Improve ESLint
ScriptCraft/pipeline/head This commit looks good Details

This commit is contained in:
TheBrokenRail 2020-04-28 10:16:47 -04:00
parent bc7dc8d5c2
commit 2539e98a44
13 changed files with 189 additions and 176 deletions

2
Jenkinsfile vendored
View File

@ -10,7 +10,7 @@ pipeline {
} }
stage('Build') { stage('Build') {
steps { steps {
sh './gradlew build typedoc' sh './gradlew build typedoc eslint'
} }
post { post {
success { success {

View File

@ -3,65 +3,6 @@ plugins {
id 'com.matthewprenger.cursegradle' version '1.4.0' id 'com.matthewprenger.cursegradle' version '1.4.0'
} }
def cDir = new File(rootProject.projectDir.absolutePath, 'src/main/c')
class JNIPlatform {
String name
String[] cmakeArgs
String libExtension
JNIPlatform(String name, String libExtension, File rootDir) {
this.name = name
this.cmakeArgs = ["-DCMAKE_TOOLCHAIN_FILE=${rootDir.absolutePath}/cmake/${name}-toolchain.cmake"] as String[]
this.libExtension = libExtension
}
}
JNIPlatform[] jniPlatforms = [
new JNIPlatform("linux-x86_64", ".so", rootDir),
new JNIPlatform("linux-x86", ".so", rootDir),
new JNIPlatform("linux-armhf", ".so", rootDir),
new JNIPlatform("linux-arm64", ".so", rootDir),
new JNIPlatform("windows-x86_64", ".dll", rootDir),
new JNIPlatform("windows-x86", ".dll", rootDir)
]
task cleanJNI {}
task compileJNI {}
for (JNIPlatform platform : jniPlatforms) {
def buildDir = new File(cDir, "build-${platform.name}")
if (!buildDir.exists()) {
buildDir.mkdir()
}
tasks.create(name: "cmake-${platform.name}", group: 'jni', type: Exec) {
workingDir buildDir
executable 'cmake'
args platform.cmakeArgs + ['..']
}
tasks.create(name: "compileJNI-${platform.name}", group: 'jni', type: Exec) {
workingDir buildDir
executable 'make'
dependsOn tasks.getByName("cmake-${platform.name}")
}
compileJNI.dependsOn tasks.getByName("compileJNI-${platform.name}")
tasks.create(name: "cleanJNI-${platform.name}", group: 'jni', type: Delete) {
delete buildDir.absolutePath
}
cleanJNI.dependsOn tasks.getByName("cleanJNI-${platform.name}")
}
clean.dependsOn cleanJNI
processResources.dependsOn compileJNI
compileJava { compileJava {
sourceCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
@ -82,72 +23,8 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
} }
def typescriptOut = new File(buildDir, 'generated/typescript') apply from: './typescript.build.gradle'
apply from: './jni.build.gradle'
sourceSets {
main {
resources {
srcDir typescriptOut
}
}
}
def typescriptRoot = 'src/main/js'
def typescriptRootFile = new File(rootDir.absolutePath, typescriptRoot)
task typescript(group: 'build') {
inputs.dir typescriptRootFile
outputs.dir typescriptOut
doFirst {
project.delete {
delete typescriptOut
}
typescriptOut.mkdirs()
project.exec {
workingDir typescriptRootFile
executable 'npm'
args 'run', 'build', '--'
args '--outDir', new File(typescriptOut, 'scriptcraft').absolutePath
}
}
}
task eslint(group: 'verification', type: Exec) {
workingDir typescriptRootFile
executable 'npm'
args 'run', 'eslint'
}
processResources.dependsOn typescript
def typedocOut = new File(buildDir, 'typedoc')
task typedoc(group: 'documentation') {
inputs.dir typescriptRootFile
outputs.dir typedocOut
doFirst {
project.delete {
delete typedocOut
}
typedocOut.mkdirs()
project.exec {
workingDir typescriptRootFile
executable 'npm'
args 'run', 'typedoc', '--'
args '--out', typedocOut.absolutePath
}
}
}
processResources { processResources {
inputs.property 'version', mod_version inputs.property 'version', mod_version
@ -161,20 +38,6 @@ processResources {
from(sourceSets.main.resources.srcDirs) { from(sourceSets.main.resources.srcDirs) {
exclude 'fabric.mod.json' exclude 'fabric.mod.json'
} }
for (JNIPlatform platform : jniPlatforms) {
def buildDir = new File(cDir, "build-${platform.name}")
if (!buildDir.exists()) {
buildDir.mkdir()
}
def file = new File(buildDir, 'libscriptcraft' + platform.libExtension)
inputs.files file
from(file.absolutePath) {
into new File('natives', platform.name).path
}
}
} }
// ensure that the encoding is set to UTF-8, no matter what the system default is // ensure that the encoding is set to UTF-8, no matter what the system default is
@ -192,16 +55,8 @@ task sourcesJar(type: Jar, dependsOn: classes) {
from sourceSets.main.allSource from sourceSets.main.allSource
} }
task typedocJar(type: Jar) {
classifier 'typedoc'
from typedocOut
}
typedocJar.dependsOn typedoc
artifacts { artifacts {
archives sourcesJar archives sourcesJar
archives typedocJar
} }
jar { jar {

74
jni.build.gradle Normal file
View File

@ -0,0 +1,74 @@
def cDir = new File(rootProject.projectDir.absolutePath, 'src/main/c')
class JNIPlatform {
String name
String[] cmakeArgs
String libExtension
JNIPlatform(String name, String libExtension, File rootDir) {
this.name = name
this.cmakeArgs = ["-DCMAKE_TOOLCHAIN_FILE=${rootDir.absolutePath}/cmake/${name}-toolchain.cmake"] as String[]
this.libExtension = libExtension
}
}
JNIPlatform[] jniPlatforms = [
new JNIPlatform("linux-x86_64", ".so", rootDir),
new JNIPlatform("linux-x86", ".so", rootDir),
new JNIPlatform("linux-armhf", ".so", rootDir),
new JNIPlatform("linux-arm64", ".so", rootDir),
new JNIPlatform("windows-x86_64", ".dll", rootDir),
new JNIPlatform("windows-x86", ".dll", rootDir)
]
task cleanJNI {}
task compileJNI {}
for (JNIPlatform platform : jniPlatforms) {
def buildDir = new File(cDir, "build-${platform.name}")
if (!buildDir.exists()) {
buildDir.mkdir()
}
tasks.create(name: "cmake-${platform.name}", group: 'jni', type: Exec) {
workingDir buildDir
executable 'cmake'
args platform.cmakeArgs + ['..']
}
tasks.create(name: "compileJNI-${platform.name}", group: 'jni', type: Exec) {
workingDir buildDir
executable 'make'
dependsOn tasks.getByName("cmake-${platform.name}")
}
compileJNI.dependsOn tasks.getByName("compileJNI-${platform.name}")
tasks.create(name: "cleanJNI-${platform.name}", group: 'jni', type: Delete) {
delete buildDir.absolutePath
}
cleanJNI.dependsOn tasks.getByName("cleanJNI-${platform.name}")
}
clean.dependsOn cleanJNI
processResources.dependsOn compileJNI
processResources {
for (JNIPlatform platform : jniPlatforms) {
def buildDir = new File(cDir, "build-${platform.name}")
if (!buildDir.exists()) {
buildDir.mkdir()
}
def file = new File(buildDir, 'libscriptcraft' + platform.libExtension)
inputs.files file
from(file.absolutePath) {
into new File('natives', platform.name).path
}
}
}

View File

@ -3,7 +3,8 @@
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
"parserOptions": { "parserOptions": {
"tsconfigRootDir": ".", "tsconfigRootDir": ".",
"project": ["./tsconfig.json"] "project": ["./tsconfig.json"],
"sourceType": "module"
}, },
"plugins": [ "plugins": [
"@typescript-eslint" "@typescript-eslint"
@ -24,6 +25,19 @@
"@typescript-eslint/no-empty-function": "off", "@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-use-before-define": "off", "@typescript-eslint/no-use-before-define": "off",
"quotes": ["error", "single"], "quotes": ["error", "single"],
"eol-last": ["error", "always"] "eol-last": ["error", "always"],
"no-eq-null": "error",
"no-unneeded-ternary": "error",
"block-spacing": "error",
"camelcase": "error",
"comma-dangle": ["error", "never"],
"func-call-spacing": ["error", "never"],
"function-call-argument-newline": ["error", "never"],
"implicit-arrow-linebreak": ["error", "beside"],
"linebreak-style": ["error", "unix"],
"no-trailing-spaces": "error",
"no-lonely-if": "error",
"no-var": "error",
"prefer-arrow-callback": "error"
} }
} }

View File

@ -8,7 +8,7 @@
"typescript": "latest" "typescript": "latest"
}, },
"scripts": { "scripts": {
"eslint": "eslint --ignore-path .gitignore src", "eslint": "eslint --ignore-path .gitignore \"src/**/*\"",
"build": "tsc", "build": "tsc",
"typedoc": "typedoc" "typedoc": "typedoc"
} }

View File

@ -157,7 +157,7 @@ export class CustomBlockEntity {
* Mark Dirty * Mark Dirty
*/ */
markDirty(): void { markDirty(): void {
if (this.getWorld() != null) { if (this.getWorld() !== null) {
useBridge('World.markBlockEntityDirty', this.getWorld().javaObject, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ()); useBridge('World.markBlockEntityDirty', this.getWorld().javaObject, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ());
} }
} }

View File

@ -25,7 +25,7 @@ export class DamageSource {
*/ */
private static build(bridge: string, value: BridgeValueType): DamageSource { private static build(bridge: string, value: BridgeValueType): DamageSource {
const obj = useBridge(bridge, value) as JavaObject; const obj = useBridge(bridge, value) as JavaObject;
if (obj != null) { if (obj !== null) {
return new DamageSource(obj); return new DamageSource(obj);
} else { } else {
return null; return null;
@ -73,9 +73,6 @@ export class Entity {
* @internal * @internal
*/ */
constructor(object: JavaObject | Entity) { constructor(object: JavaObject | Entity) {
if (object == null) {
return null;
}
if (object instanceof Entity) { if (object instanceof Entity) {
this.javaObject = object.javaObject; this.javaObject = object.javaObject;
} else { } else {
@ -89,7 +86,7 @@ export class Entity {
*/ */
getEntityWorld(): World { getEntityWorld(): World {
const obj = useBridge('Entity.getEntityWorld', this.javaObject) as JavaObject; const obj = useBridge('Entity.getEntityWorld', this.javaObject) as JavaObject;
if (obj != null) { if (obj !== null) {
return new World(obj); return new World(obj);
} else { } else {
return null; return null;
@ -102,7 +99,7 @@ export class Entity {
*/ */
getID(): Identifier { getID(): Identifier {
const obj = useBridge('Entity.getID', this.javaObject) as string; const obj = useBridge('Entity.getID', this.javaObject) as string;
if (obj != null) { if (obj !== null) {
return new Identifier(obj); return new Identifier(obj);
} else { } else {
return null; return null;
@ -185,7 +182,7 @@ export class Entity {
*/ */
getPosition(): Pos { getPosition(): Pos {
const pos: number[] = useBridge('Entity.getPosition', this.javaObject) as number[]; const pos: number[] = useBridge('Entity.getPosition', this.javaObject) as number[];
if (pos != null && pos.length === 3) { if (pos !== null && pos.length === 3) {
return new Pos(pos[0], pos[1], pos[2]); return new Pos(pos[0], pos[1], pos[2]);
} else { } else {
return null; return null;
@ -206,7 +203,7 @@ export class Entity {
*/ */
toTag(): CompoundTag { toTag(): CompoundTag {
const obj = useBridge('Entity.toTag', this.javaObject) as JavaObject; const obj = useBridge('Entity.toTag', this.javaObject) as JavaObject;
if (obj != null) { if (obj !== null) {
return new CompoundTag(obj); return new CompoundTag(obj);
} else { } else {
return null; return null;

View File

@ -1,6 +1,6 @@
/** /**
* API Entry-Point * API Entry-Point
* *
* Import With: * Import With:
* ```typescript * ```typescript
* import { ... } from 'minecraft'; * import { ... } from 'minecraft';

View File

@ -27,7 +27,7 @@ export class ItemStack {
*/ */
static create(item: Identifier, count?: number): ItemStack { static create(item: Identifier, count?: number): ItemStack {
const obj = useBridge('ItemStack.create', item.toString(), count ? count : 1) as JavaObject; const obj = useBridge('ItemStack.create', item.toString(), count ? count : 1) as JavaObject;
if (obj != null) { if (obj !== null) {
return new ItemStack(obj); return new ItemStack(obj);
} else { } else {
return null; return null;
@ -40,7 +40,7 @@ export class ItemStack {
*/ */
getItem(): Identifier { getItem(): Identifier {
const obj = useBridge('ItemStack.getItem', this.javaObject) as string; const obj = useBridge('ItemStack.getItem', this.javaObject) as string;
if (obj != null) { if (obj !== null) {
return new Identifier(obj); return new Identifier(obj);
} else { } else {
return null; return null;
@ -101,7 +101,7 @@ export class ItemStack {
*/ */
getTag(): CompoundTag { getTag(): CompoundTag {
const obj = useBridge('ItemStack.getTag', this.javaObject) as JavaObject; const obj = useBridge('ItemStack.getTag', this.javaObject) as JavaObject;
if (obj != null) { if (obj !== null) {
return new CompoundTag(obj); return new CompoundTag(obj);
} else { } else {
return null; return null;
@ -122,7 +122,7 @@ export class ItemStack {
*/ */
toTag(): CompoundTag { toTag(): CompoundTag {
const obj = useBridge('ItemStack.toTag', this.javaObject) as JavaObject; const obj = useBridge('ItemStack.toTag', this.javaObject) as JavaObject;
if (obj != null) { if (obj !== null) {
return new CompoundTag(obj); return new CompoundTag(obj);
} else { } else {
return null; return null;
@ -136,7 +136,7 @@ export class ItemStack {
*/ */
static fromTag(tag: CompoundTag): ItemStack { static fromTag(tag: CompoundTag): ItemStack {
const obj = useBridge('ItemStack.fromTag', tag.javaObject) as JavaObject; const obj = useBridge('ItemStack.fromTag', tag.javaObject) as JavaObject;
if (obj != null) { if (obj !== null) {
return new ItemStack(obj); return new ItemStack(obj);
} else { } else {
return null; return null;
@ -322,5 +322,5 @@ addBridge('CustomItem.onUseOnBlock', (id: string, world: JavaObject, x: number,
}); });
addBridge('CustomItem.onUseOnEntity', (id: string, player: JavaObject, target: JavaObject, hand: keyof typeof Hand): boolean => { addBridge('CustomItem.onUseOnEntity', (id: string, player: JavaObject, target: JavaObject, hand: keyof typeof Hand): boolean => {
return ItemRegistry.INSTANCE.get(new Identifier(id)).onUseOnEntity(new PlayerEntity(player), new LivingEntity(target), Hand[hand]) === ActionResult.SUCCESS ? true : false; return ItemRegistry.INSTANCE.get(new Identifier(id)).onUseOnEntity(new PlayerEntity(player), new LivingEntity(target), Hand[hand]) === ActionResult.SUCCESS;
}); });

View File

@ -86,7 +86,7 @@ export class CompoundTag {
set(key: string, value: number, numberType: NumberType): void; set(key: string, value: number, numberType: NumberType): void;
set(key: string, value: Exclude<TagType, number>): void; set(key: string, value: Exclude<TagType, number>): void;
set(key: string, value: TagType, numberType?: NumberType): void { set(key: string, value: TagType, numberType?: NumberType): void {
useBridge('CompoundTag.set', this.javaObject, key, value instanceof CompoundTag || value instanceof ListTag ? value.javaObject : value, numberType != null ? numberType : NumberType.DOUBLE); useBridge('CompoundTag.set', this.javaObject, key, value instanceof CompoundTag || value instanceof ListTag ? value.javaObject : value, numberType !== null ? numberType : NumberType.DOUBLE);
} }
/** /**
@ -103,7 +103,7 @@ export class CompoundTag {
*/ */
static create(): CompoundTag { static create(): CompoundTag {
const obj = useBridge('CompoundTag.create') as JavaObject; const obj = useBridge('CompoundTag.create') as JavaObject;
if (obj != null) { if (obj !== null) {
return new CompoundTag(obj); return new CompoundTag(obj);
} else { } else {
return null; return null;
@ -148,7 +148,7 @@ export class ListTag {
set(key: number, value: number, numberType: NumberType): void; set(key: number, value: number, numberType: NumberType): void;
set(key: number, value: Exclude<TagType, number>): void; set(key: number, value: Exclude<TagType, number>): void;
set(key: number, value: TagType, numberType?: NumberType): void { set(key: number, value: TagType, numberType?: NumberType): void {
useBridge('ListTag.set', this.javaObject, key, value instanceof CompoundTag || value instanceof ListTag ? value.javaObject : value, numberType != null ? numberType : NumberType.DOUBLE); useBridge('ListTag.set', this.javaObject, key, value instanceof CompoundTag || value instanceof ListTag ? value.javaObject : value, numberType !== null ? numberType : NumberType.DOUBLE);
} }
/** /**
@ -165,7 +165,7 @@ export class ListTag {
*/ */
static create(): ListTag { static create(): ListTag {
const obj = useBridge('ListTag.create') as JavaObject; const obj = useBridge('ListTag.create') as JavaObject;
if (obj != null) { if (obj !== null) {
return new ListTag(obj); return new ListTag(obj);
} else { } else {
return null; return null;

View File

@ -36,7 +36,7 @@ export class World {
*/ */
getBlockState(pos: Pos): BlockState { getBlockState(pos: Pos): BlockState {
const obj = useBridge('World.getBlockState', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as JavaObject; const obj = useBridge('World.getBlockState', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as JavaObject;
if (obj != null) { if (obj !== null) {
return new BlockState(obj); return new BlockState(obj);
} else { } else {
return null; return null;
@ -50,7 +50,7 @@ export class World {
*/ */
spawnEntity(id: Identifier, pos: Pos): Entity { spawnEntity(id: Identifier, pos: Pos): Entity {
const obj = useBridge('World.spawnEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ(), id.toString()) as JavaObject; const obj = useBridge('World.spawnEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ(), id.toString()) as JavaObject;
if (obj != null) { if (obj !== null) {
return new Entity(obj); return new Entity(obj);
} else { } else {
return null; return null;
@ -64,7 +64,7 @@ export class World {
*/ */
getCustomBlockEntity(pos: Pos): CustomBlockEntity { getCustomBlockEntity(pos: Pos): CustomBlockEntity {
const obj = useBridge('World.getCustomBlockEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as number; const obj = useBridge('World.getCustomBlockEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as number;
if (obj != null) { if (obj !== null) {
return BlockRegistry.INSTANCE.getCustomBlockEntity(obj); return BlockRegistry.INSTANCE.getCustomBlockEntity(obj);
} else { } else {
return null; return null;
@ -78,7 +78,7 @@ export class World {
*/ */
getBlockEntity(pos: Pos): Identifier { getBlockEntity(pos: Pos): Identifier {
const obj = useBridge('World.getBlockEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as string; const obj = useBridge('World.getBlockEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as string;
if (obj != null) { if (obj !== null) {
return new Identifier(obj); return new Identifier(obj);
} else { } else {
return null; return null;

View File

@ -29,6 +29,6 @@ declare const console: Console;
declare module 'scriptcraft-core' { declare module 'scriptcraft-core' {
function addBridge(name: string, bridge: BridgeType): void; function addBridge(name: string, bridge: BridgeType): void;
function useBridge(name: string, ...args: BridgeValueType[]): BridgeValueType; function useBridge(name: string, ...args: BridgeValueType[]): BridgeValueType;
} }

73
typescript.build.gradle Normal file
View File

@ -0,0 +1,73 @@
def typescriptOut = new File(buildDir, 'generated/typescript')
def typescriptRoot = 'src/main/js'
def typescriptRootFile = new File(rootDir.absolutePath, typescriptRoot)
task typescript(group: 'build') {
inputs.dir typescriptRootFile
outputs.dir typescriptOut
doFirst {
project.delete {
delete typescriptOut
}
typescriptOut.mkdirs()
project.exec {
workingDir typescriptRootFile
executable 'npm'
args 'run', 'build', '--'
args '--outDir', new File(typescriptOut, 'scriptcraft').absolutePath
}
}
}
task eslint(group: 'verification', type: Exec) {
workingDir typescriptRootFile
executable 'npm'
args 'run', 'eslint'
}
processResources.dependsOn typescript
def typedocOut = new File(buildDir, 'typedoc')
task typedoc(group: 'documentation') {
inputs.dir typescriptRootFile
outputs.dir typedocOut
doFirst {
project.delete {
delete typedocOut
}
typedocOut.mkdirs()
project.exec {
workingDir typescriptRootFile
executable 'npm'
args 'run', 'typedoc', '--'
args '--out', typedocOut.absolutePath
}
}
}
processResources {
from typescriptOut.absolutePath
}
task typedocJar(type: Jar) {
classifier 'typedoc'
from typedocOut
}
typedocJar.dependsOn typedoc
artifacts {
archives typedocJar
}