Skip to content
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
49 changes: 49 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Lint
on:
push:
branches:
- master
pull_request:

jobs:
lint-js:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: Set up Node
uses: actions/setup-node@v1
- name: Set up Stylelint Problem Matcher
uses: xt0rted/stylelint-problem-matcher@v1
- name: Install Dependencies
run: npm ci
- name: lint JavaScript
run: make lint-js
- name: lint Stylesheets
run: make lint-css
- name: build JavaScript
run: make build-js-production
env:
CI: true

lint-xml:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: Setup xmllint
run: sudo apt-get install --no-install-recommends -y libxml2-utils
- name: lint XML
run: make lint-xml

lint-php:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
- name: Set up php${{ matrix.php-versions }}
uses: shivammathur/setup-php@master
- name: Install Dependencies
run: composer install --prefer-dist
- name: lint PHP
run: make lint-php
11 changes: 11 additions & 0 deletions .phan/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'directory_list' => [
'lib/',
'vendor/',
],
"exclude_analysis_directory_list" => [
'vendor/',
],
];
21 changes: 21 additions & 0 deletions .phan/to-annotation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

$json = file_get_contents('php://stdin');
$items = json_decode($json);
$errors = 0;

foreach ($items as $item) {
$type = ($item->severity >= 10 ? 'error' : 'warning');
echo '::' . $type;
echo ' file=' . $item->location->path;
echo ',line=' . $item->location->lines->begin;
$message = explode(' ', $item->description, 3);
echo '::' . $message[2] . ' ['.$message[1].']';
echo PHP_EOL;
if ($type === 'error') {
$errors++;
}
}

exit($errors);

2 changes: 0 additions & 2 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ build:
tests:
override:
- php-scrutinizer-run
- phpcs-run --standard=phpcs.xml appinfo/ lib/
- eslint-run --ext .js,.vue src

tools:
external_code_coverage: false
Expand Down
53 changes: 0 additions & 53 deletions .travis.yml

This file was deleted.

10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,28 @@ test-coverage:
npm run test:coverage

# Linting
lint: lint-php lint-js lint-css lint-nextcloud
lint: lint-php lint-js lint-css lint-xml

lint-php:
# Check PHP syntax errors
@! find lib/ -name "*.php" | xargs -I{} php -l '{}' | grep -v "No syntax errors detected"
# PHP CodeSniffer
vendor/bin/phpcs --standard=phpcs.xml --runtime-set ignore_warnings_on_exit 1 appinfo/ lib/
# PHAN
vendor/phan/phan/phan --allow-polyfill-parser -k .phan/config.php --no-progress-bar -m json | php .phan/to-annotation.php
# Check min-version consistency
php tests/nextcloud-version.php

lint-js:
npm run lint

lint-css:
npm run stylelint

lint-nextcloud:
lint-xml:
# Check info.xml schema validity
wget https://apps.nextcloud.com/schema/apps/info.xsd -P appinfo/ -N --no-verbose || [ -f appinfo/info.xsd ]
xmllint appinfo/info.xml --schema appinfo/info.xsd --noout
# Check min-version consistency
php tests/nextcloud-version.php

# Fix lint
lint-fix: lint-php-fix lint-js-fix lint-css-fix
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"require-dev": {
"christophwurst/nextcloud": "^15.0",
"squizlabs/php_codesniffer": "3.*"
"squizlabs/php_codesniffer": "3.*",
"phan/phan": "^2.0"
}
}
4 changes: 2 additions & 2 deletions lib/Controller/NotesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function get($id) {
$this->userId,
$this->appName,
'notesLastViewedNote',
$id
strval($id)
);

$note = $this->notesService->get($id, $this->userId);
Expand Down Expand Up @@ -180,7 +180,7 @@ public function category($id, $category) {
*/
public function favorite($id, $favorite) {
$result = $this->notesService->favorite($id, $favorite, $this->userId);
return new DataResponse($result);
return new DataResponse($result); // @phan-suppress-current-line PhanTypeMismatchArgument
}


Expand Down
3 changes: 0 additions & 3 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@

use OCP\AppFramework\Controller;

use OCP\IConfig;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Files\IRootFolder;
use OCP\AppFramework\Http\JSONResponse;
use OCA\Notes\Service\SettingsService;

Expand Down
9 changes: 5 additions & 4 deletions lib/Db/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Note extends Entity {
public $error = false;
public $errorMessage='';

private const TAG_FAVORITE = \OC\Tags::TAG_FAVORITE; // @phan-suppress-current-line PhanUndeclaredClassConstant

public function __construct() {
$this->addType('modified', 'integer');
$this->addType('favorite', 'boolean');
Expand All @@ -54,7 +56,6 @@ public static function fromFile(File $file, Folder $notesFolder, $tags = [], $on
$fileContent=$file->getContent();
$note->setContent(self::convertEncoding($fileContent));
}
$note->setModified($file->getMTime());
if (!$onlyMeta) {
$note->updateETag();
}
Expand All @@ -72,7 +73,6 @@ public static function fromException($message, File $file, Folder $notesFolder,
$note->setErrorMessage($message);
$note->setError(true);
$note->setContent($message);
$note->setModified(null);
$note->resetUpdatedFields();
return $note;
}
Expand All @@ -87,11 +87,12 @@ private static function convertEncoding($str) {
private function initCommonBaseFields(File $file, Folder $notesFolder, $tags) {
$this->setId($file->getId());
$this->setTitle(pathinfo($file->getName(), PATHINFO_FILENAME)); // remove extension
$this->setModified($file->getMTime());
$subdir = substr(dirname($file->getPath()), strlen($notesFolder->getPath())+1);
$this->setCategory($subdir ? $subdir : '');
if (is_array($tags) && in_array(\OC\Tags::TAG_FAVORITE, $tags)) {
if (is_array($tags) && in_array(self::TAG_FAVORITE, $tags)) {
$this->setFavorite(true);
//unset($tags[array_search(\OC\Tags::TAG_FAVORITE, $tags)]);
//unset($tags[array_search(self::TAG_FAVORITE, $tags)]);
}
}

Expand Down
1 change: 0 additions & 1 deletion lib/Service/MetaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace OCA\Notes\Service;

use OCA\Notes\Db\Note;
use OCA\Notes\Db\Meta;
use OCA\Notes\Db\MetaMapper;

Expand Down
19 changes: 12 additions & 7 deletions lib/Service/NoteUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,37 @@

namespace OCA\Notes\Service;

use OCP\IDBConnection;
use OCP\IL10N;
use OCP\ILogger;
use OCP\Encryption\Exceptions\GenericEncryptionException;
use OCP\Files\IRootFolder;
use OCP\Files\FileInfo;
use OCP\Files\File;
use OCP\Files\Folder;

use OCA\Notes\Db\Note;

class NoteUtil {

private $db;
private $l10n;
private $root;
private $logger;
private $appName;

/**
* @param IDBConnection $db
* @param IRootFolder $root
* @param IL10N $l10n
* @param ILogger $logger
* @param String $appName
*/
public function __construct(
IDBConnection $db,
IRootFolder $root,
IL10N $l10n,
ILogger $logger,
$appName
) {
$this->db = $db;
$this->root = $root;
$this->l10n = $l10n;
$this->logger = $logger;
Expand All @@ -44,7 +46,7 @@ public function gatherNoteFiles(Folder $folder) : array {
$notes = [];
$nodes = $folder->getDirectoryListing();
foreach ($nodes as $node) {
if ($node->getType() === FileInfo::TYPE_FOLDER) {
if ($node->getType() === FileInfo::TYPE_FOLDER && $node instanceof Folder) {
$notes = array_merge($notes, $this->gatherNoteFiles($node));
continue;
}
Expand All @@ -59,7 +61,7 @@ public function gatherNoteFiles(Folder $folder) : array {
/**
* test if file is a note
*/
public function isNote(File $file) : bool {
public function isNote(FileInfo $file) : bool {
$allowedExtensions = ['txt', 'org', 'markdown', 'md', 'note'];
$ext = strtolower(pathinfo($file->getName(), PATHINFO_EXTENSION));
return $file->getType() === 'file' && in_array($ext, $allowedExtensions);
Expand Down Expand Up @@ -96,7 +98,10 @@ public function moveNote(Folder $notesFolder, File $file, $category, string $tit
$file->move($newFilePath);
}
if ($currentBasePath !== $basePath) {
$this->deleteEmptyFolder($notesFolder, $this->root->get($currentBasePath));
$fileBasePath = $this->root->get($currentBasePath);
if ($fileBasePath instanceof Folder) {
$this->deleteEmptyFolder($notesFolder, $fileBasePath);
}
}
}

Expand Down Expand Up @@ -171,7 +176,7 @@ public function sanitisePath(string $str) : string {

// if mysql doesn't support 4byte UTF-8, then remove those characters
// see \OC\Files\Storage\Common::verifyPath(...)
if (!\OC::$server->getDatabaseConnection()->supports4ByteText()) {
if (!$this->db->supports4ByteText()) {
$str = preg_replace('%(?:
\xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
| [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
Expand Down
1 change: 0 additions & 1 deletion lib/Service/NotesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use OCP\Encryption\Exceptions\GenericEncryptionException;
use OCP\Files\File;
use OCP\Files\FileInfo;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\IConfig;
Expand Down
7 changes: 0 additions & 7 deletions lib/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@

namespace OCA\Notes\Service;

use OCP\AppFramework\Controller;

use OCP\IConfig;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Files\IRootFolder;
use OCP\AppFramework\Http\JSONResponse;

class SettingsService {

Expand Down
1 change: 1 addition & 0 deletions src/components/EditorMarkdownIt.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<template>
<!-- eslint-disable-next-line vue/no-v-html -->
<div class="note-preview" v-html="html" />
</template>
<script>
Expand Down