Skip to content

Commit

Permalink
refactor: esling config added
Browse files Browse the repository at this point in the history
  • Loading branch information
NickIliev committed Mar 20, 2018
1 parent 2af208a commit ce0f63c
Show file tree
Hide file tree
Showing 23 changed files with 387 additions and 124 deletions.
7 changes: 7 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# /node_modules/* and /bower_components/* ignored by default

app/App_Resources/*
hooks/*
platforms/*
dist/*
scripts/*
233 changes: 233 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
{
"env": {
"node": true,
"es6": true
},
"globals": {
"global": true
},
"extends": "eslint:recommended",
"rules": {
"accessor-pairs": "error",
"array-bracket-spacing": "error",
"arrow-body-style": "error",
"arrow-parens": "error",
"arrow-spacing": "error",
"block-spacing": "error",
"brace-style": [
"error",
"stroustrup",
{ "allowSingleLine": true }
],
"camelcase": "error",
"comma-dangle": "error",
"comma-spacing": "error",
"comma-style": "error",
"complexity": "error",
"computed-property-spacing": "error",
"curly": "error",
"default-case": "error",
"dot-location": [
"error",
"property"
],
"dot-notation": "error",
"eol-last": "error",
"eqeqeq": "error",
"func-call-spacing": "error",
"generator-star-spacing": "error",
"guard-for-in": "error",
"handle-callback-err": "error",
"id-blacklist": "error",
"id-match": "error",
"keyword-spacing": "error",
"max-depth": "error",
"max-nested-callbacks": "error",
"max-statements-per-line": "error",
"new-parens": "error",
"newline-per-chained-call": "off",
"no-alert": "error",
"no-array-constructor": "error",
"no-bitwise": [
"error",
{
"int32Hint": true
}
],
"no-caller": "error",
"no-catch-shadow": "error",
"no-confusing-arrow": "error",
"no-console": "off",
"no-continue": "off",
"no-div-regex": "error",
"no-duplicate-imports": "error",
"no-else-return": "off",
"no-empty-function": "off",
"no-eq-null": "off",
"no-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-label": "error",
"no-extra-parens": "off",
"no-floating-decimal": "error",
"no-global-assign": "error",
"no-implicit-coercion": [
"error",
{
"boolean": false,
"number": false,
"string": false
}
],
"no-implicit-globals": "error",
"no-implied-eval": "error",
"no-inline-comments": "off",
"no-inner-declarations": [
"error",
"functions"
],
"no-invalid-this": "off",
"no-iterator": "error",
"no-label-var": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-lonely-if": "off",
"no-loop-func": "error",
"no-magic-numbers": "off",
"no-mixed-operators": "error",
"no-mixed-requires": "error",
"no-multi-spaces": "error",
"no-multi-str": "error",
"no-multiple-empty-lines": "error",
"no-negated-condition": "off",
"no-nested-ternary": "error",
"no-new": "error",
"no-new-func": "error",
"no-new-object": "error",
"no-new-require": "error",
"no-new-wrappers": "error",
"no-octal-escape": "error",
"no-param-reassign": "off",
"no-path-concat": "error",
"no-plusplus": "off",
"no-process-env": "off",
"no-process-exit": "off",
"no-proto": "off",
"no-prototype-builtins": "off",
"no-restricted-globals": "error",
"no-restricted-imports": "error",
"no-restricted-modules": "error",
"no-restricted-syntax": "error",
"no-return-assign": [
"error",
"except-parens"
],
"no-script-url": "error",
"no-self-compare": "error",
"no-sequences": "error",
"no-shadow": "off",
"no-shadow-restricted-names": "error",
"no-spaced-func": "error",
"no-sync": "off",
"no-tabs": "off",
"no-template-curly-in-string": "error",
"no-ternary": "off",
"no-throw-literal": "error",
"no-trailing-spaces": "error",
"no-undef-init": "off",
"no-undefined": "off",
"no-underscore-dangle": "off",
"no-unmodified-loop-condition": "error",
"no-unneeded-ternary": "off",
"no-unsafe-negation": "error",
"no-unused-expressions": "error",
"no-unused-vars": [
"error",
{
"vars": "all",
"args": "none",
"ignoreRestSiblings": false
}
],
"no-use-before-define": "off",
"no-useless-call": "off",
"no-useless-computed-key": "error",
"no-useless-concat": "error",
"no-useless-constructor": "error",
"no-useless-escape": "off",
"no-useless-rename": "error",
"no-var": "error",
"no-void": "off",
"no-warning-comments": "off",
"no-whitespace-before-property": "error",
"no-with": "error",
"object-curly-newline": "off",
"object-curly-spacing": [
"error",
"always"
],
"object-property-newline": "error",
"object-shorthand": "off",
"one-var": [
"error",
"never"
],
"one-var-declaration-per-line": "off",
"operator-assignment": "off",
"operator-linebreak": [
"error",
"after"
],
"padded-blocks": "off",
"padding-line-between-statements": [
"error",
{
"blankLine": "always",
"prev": "*",
"next": "return"
}
],
"prefer-arrow-callback": "error",
"prefer-const": "error",
"prefer-spread": "error",
"prefer-template": "error",
"quotes": "error",
"radix": "error",
"rest-spread-spacing": "error",
"semi": "error",
"semi-spacing": [
"error",
{
"after": true,
"before": false
}
],
"sort-imports": "error",
"space-before-blocks": "error",
"space-in-parens": [
"error",
"never"
],
"space-infix-ops": "error",
"space-unary-ops": "error",
"strict": "error",
"template-curly-spacing": "error",
"unicode-bom": [
"error",
"never"
],
"wrap-iife": "error",
"wrap-regex": "error",
"yield-star-spacing": "error",
"yoda": [
"error",
"never"
]
},
"parserOptions": {
"ecmaVersion": 6,
"ecmaFeatures": {
"impliedStrict": true
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

var applicationModule = require("tns-core-modules/application");
var Observable = require("tns-core-modules/data/observable").Observable;
var platformModule = require("tns-core-modules/platform");
var vm, receiver;
const applicationModule = require("tns-core-modules/application");
const Observable = require("tns-core-modules/data/observable").Observable;
const platformModule = require("tns-core-modules/platform");
let vm;
let receiver;
function onNavigatingTo(args) {
var page = args.object;
const page = args.object;
page.actionBar.title = "";
vm = new Observable();
vm.set("info", "Using Android Broadcast Receiver \nto check the battery life");
Expand All @@ -19,10 +20,10 @@ function onNavigatedTo(args) {
// >> broadcast-receiver
if (platformModule.isAndroid) {
// use tns-platform-dclarations to acces native APIs (e.g. ndroid.content.Intent)
receiver = applicationModule.android.registerBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED, function onReceiveCallback(context, intent) {
var level = intent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, -1);
var scale = intent.getIntExtra(android.os.BatteryManager.EXTRA_SCALE, -1);
var percent = (level / scale) * 100.0;
receiver = applicationModule.android.registerBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED, (context, intent) => {
const level = intent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, -1);
const scale = intent.getIntExtra(android.os.BatteryManager.EXTRA_SCALE, -1);
const percent = (level / scale) * 100.0;
vm.set("batteryLife", percent.toString());
});
}
Expand Down
48 changes: 28 additions & 20 deletions app/application/application-events/application-events-page.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
// >> application-events-import
var applicationModule = require("tns-core-modules/application");
const applicationModule = require("tns-core-modules/application");
// << application-events-import
var Observable = require("tns-core-modules/data/observable").Observable;
var enums = require("ui/enums");
var vm;
var launchListener, suspendListener, resumeListener, exitListener, displayedListener, lowMemoryListener, orientationChangedListener, uncaughtErrorListener;
const Observable = require("tns-core-modules/data/observable").Observable;
const enums = require("ui/enums");
let vm;
let launchListener;
let suspendListener;
let resumeListener;
let exitListener;
let displayedListener;
let lowMemoryListener;
let orientationChangedListener;
let uncaughtErrorListener;

function onNavigatingTo(args) {
var page = args.object;
const page = args.object;
vm = new Observable();
vm.set("actionBarTitle", args.context.actionBarTitle);
vm.set("info", "Refer to the code-behind files \nfor Application Events snippets");
if (applicationModule.android) {
var activity = applicationModule.android.foregroundActivity;
var orientationEnum = activity.getResources().getConfiguration().orientation;
const activity = applicationModule.android.foregroundActivity;
const orientationEnum = activity.getResources().getConfiguration().orientation;
vm.set("orientation", (orientationEnum === 1 ? enums.DeviceOrientation.portrait : enums.DeviceOrientation.landscape));
}
else if (applicationModule.ios) {
Expand All @@ -24,36 +32,36 @@ function onNavigatingTo(args) {
exports.onNavigatingTo = onNavigatingTo;
function onGridLoaded(args) {
// >> application-events
launchListener = applicationModule.on(applicationModule.launchEvent, function (args) {
launchListener = applicationModule.on(applicationModule.launchEvent, (args) => {
// The root view for this Window on iOS or Activity for Android.
// If not set a new Frame will be created as a root view in order to maintain backwards compatibility.
console.log("Root View: " + args.root);
console.log("Root View: ", args.root);
console.log("The appication was launched!");
});
suspendListener = applicationModule.on(applicationModule.suspendEvent, function (args) {
suspendListener = applicationModule.on(applicationModule.suspendEvent, (args) => {
console.log("The appication was suspended!");
});
resumeListener = applicationModule.on(applicationModule.resumeEvent, function (args) {
resumeListener = applicationModule.on(applicationModule.resumeEvent, (args) => {
console.log("The appication was resumed!");
});
exitListener = applicationModule.on(applicationModule.exitEvent, function (args) {
exitListener = applicationModule.on(applicationModule.exitEvent, (args) => {
console.log("The appication was closed!");
});
displayedListener = applicationModule.on(applicationModule.displayedEvent, function (args) {
displayedListener = applicationModule.on(applicationModule.displayedEvent, (args) => {
console.log("NativeScript displayedEvent");
});
lowMemoryListener = applicationModule.on(applicationModule.lowMemoryEvent, function (args) {
lowMemoryListener = applicationModule.on(applicationModule.lowMemoryEvent, (args) => {
// the instance that has raidsed the event
console.log("Instance: " + args.object);
console.log("Instance: ", args.object);
});
orientationChangedListener = applicationModule.on(applicationModule.orientationChangedEvent, function (args) {
orientationChangedListener = applicationModule.on(applicationModule.orientationChangedEvent, (args) => {
// orientationChangedEventData.newValue: "portrait" | "landscape" | "unknown"
console.log("Orientation: " + args.newValue);
console.log("Orientation: ", args.newValue);
vm.set("orientation", args.newValue);
});
uncaughtErrorListener = applicationModule.on(applicationModule.uncaughtErrorEvent, function (args) {
uncaughtErrorListener = applicationModule.on(applicationModule.uncaughtErrorEvent, (args) => {
// UnhandledErrorEventData.error: NativeScriptError
console.log("NativeScript Error: " + args.error);
console.log("NativeScript Error: ", args.error);
});
// << application-events
}
Expand Down
13 changes: 8 additions & 5 deletions app/application/application-page.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
var ListViewLinksModel = require("../links-view-model");
var link = require("../link");
var navigationLinks = [
const ListViewLinksModel = require("../links-view-model");
const link = require("../link");
const navigationLinks = [
new link("Check Platform", "/application/check-platform/check-platform-page"),
new link("Application Events", "/application/application-events/application-events-page"),
new link("Android Broadcast Receiver", "/application/android-broadcast-receiver/android-broadcast-receiver-page"),
new link("iOS Notification Observer", "/application/ios-notification-observer/ios-notification-observer-page")
];
function onNavigatingTo(args) {
var page = args.object;
page.bindingContext = new ListViewLinksModel({ links: navigationLinks, actionBarTitle: args.context.title });
const page = args.object;
page.bindingContext = new ListViewLinksModel({
links: navigationLinks,
actionBarTitle: args.context.title
});
}
exports.onNavigatingTo = onNavigatingTo;
Loading

0 comments on commit ce0f63c

Please sign in to comment.