Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@studyportals/code-style

Package Overview
Dependencies
Maintainers
22
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@studyportals/code-style - npm Package Compare versions

Comparing version 2.0.0-alpha.0 to 2.0.0

examples/typescript.ts

440

.eslintrc.js
//http://eslint.org/docs/rules/
module.exports = {
"env": {
"es6": true,
"node": true,
"browser": true
env: {
es6: true,
node: true,
browser: true
},
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2017
parserOptions: {
sourceType: "module",
ecmaVersion: 2017
},
"extends": "eslint:recommended",
"rules": {
"no-console": ["error", {
allow: [
"warn",
"dir",
"time",
"timeEnd",
"timeLog",
"trace",
"assert",
"clear",
"count",
"countReset",
"group",
"groupEnd",
"table",
"dirxml",
"error",
"groupCollapsed",
"Console",
"profile",
"profileEnd",
"timeStamp",
"context"
]
}],
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"]
},
overrides: [{
files: ["*.ts", "*.tsx"],
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": [
"eslint-plugin-import",
"eslint-plugin-jsdoc",
"eslint-plugin-prefer-arrow",
"@typescript-eslint",
"@typescript-eslint/tslint"
],
"rules": {
"@typescript-eslint/adjacent-overload-signatures": "off",
"@typescript-eslint/array-type": [
"error",
{
"default": "array"
}
],
"@typescript-eslint/ban-types": [
"error",
{
"types": {
"Object": {
"message": "Avoid using the `Object` type. Did you mean `object`?"
},
"Function": {
"message": "Avoid using the `Function` type. Prefer a specific function type, like `() => void`."
},
"Boolean": {
"message": "Avoid using the `Boolean` type. Did you mean `boolean`?"
},
"Number": {
"message": "Avoid using the `Number` type. Did you mean `number`?"
},
"String": {
"message": "Avoid using the `String` type. Did you mean `string`?"
},
"Symbol": {
"message": "Avoid using the `Symbol` type. Did you mean `symbol`?"
}
}
}
],
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/dot-notation": "off",
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/indent": [
"error",
"tab"
],
"@typescript-eslint/member-ordering": "off",
"@typescript-eslint/naming-convention": [
"error",
{
"selector": 'variable',
"format": ['camelCase', 'UPPER_CASE', 'snake_case'],
"leadingUnderscore": 'allow',
"trailingUnderscore": 'forbid',
},
{
"selector": 'function',
"format": ['camelCase'],
"leadingUnderscore": 'allow',
"trailingUnderscore": 'forbid',
},
{
"selector": 'typeLike',
"format": ['PascalCase'],
},
{
"selector": 'enumMember',
"format": ['UPPER_CASE']
}
],
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/no-unused-expressions": "error",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "error",
"@typescript-eslint/prefer-function-type": "off",
"@typescript-eslint/prefer-namespace-keyword": "off",
"@typescript-eslint/triple-slash-reference": [
"error",
{
"path": "always",
"types": "prefer-import",
"lib": "always"
}
],
"@typescript-eslint/unified-signatures": "error",
"@typescript-eslint/no-shadow": [
"error",
{
"hoist": "all"
}
],
"@typescript-eslint/no-unsafe-member-access": "warn",
"arrow-parens": [
"off",
"always"
],
"comma-dangle": [
"error",
{
"objects": "never",
"arrays": "never",
"functions": "never"
}
],
"complexity": "off",
"constructor-super": "error",
"eol-last": "off",
"eqeqeq": [
"error",
"smart"
],
"guard-for-in": "off",
"id-denylist": [
"error",
"any",
"Number",
"number",
"String",
"string",
"Boolean",
"boolean",
"Undefined",
"undefined"
],
"id-match": "off",
"import/order": "off",
"jsdoc/check-alignment": "error",
"jsdoc/check-indentation": "error",
"jsdoc/newline-after-description": "error",
"max-classes-per-file": [
"error",
1
],
"max-len": [
"warn",
{
"code": 140
}
],
"new-parens": "off",
"no-bitwise": "error",
"no-caller": "error",
"no-cond-assign": "error",
extends: "eslint:recommended",
rules: {
"no-console": [
"error",
{
"allow": [
allow: [
"warn",

@@ -230,41 +42,195 @@ "dir",

],
"no-debugger": "error",
"no-empty": "error",
"no-eval": "error",
"no-fallthrough": "error",
"no-invalid-this": "off",
"no-new-wrappers": "error",
"no-shadow": "off",
"no-throw-literal": "error",
"no-trailing-spaces": "error",
"no-undef-init": "off",
"no-underscore-dangle": "error",
"no-unsafe-finally": "error",
"no-unused-labels": "error",
"no-var": "error",
"object-shorthand": "error",
"one-var": "off",
"prefer-arrow/prefer-arrow-functions": "error",
"prefer-const": "error",
"radix": "off",
"spaced-comment": "off",
"use-isnan": "off",
"valid-typeof": ["error", { "requireStringLiterals": false }],
"@typescript-eslint/tslint/config": [
"error",
{
"rules": {
"whitespace": [
true,
"check-branch",
"check-preblock",
"check-decl",
"check-type",
"check-typecast",
"check-module"
]
}
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"]
},
overrides: [
{
files: ["*.ts", "*.tsx"],
extends: [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking"
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "tsconfig.json",
sourceType: "module"
},
plugins: [
"eslint-plugin-import",
"eslint-plugin-jsdoc",
"eslint-plugin-prefer-arrow"
],
rules: {
"@typescript-eslint/adjacent-overload-signatures": "off",
"@typescript-eslint/array-type": [
"error",
{
default: "array"
}
],
"@typescript-eslint/ban-types": [
"error",
{
types: {
Object: {
message:
"Avoid using the `Object` type. Did you mean `object`?"
},
Function: {
message:
"Avoid using the `Function` type. Prefer a specific function type, like `() => void`."
},
Boolean: {
message:
"Avoid using the `Boolean` type. Did you mean `boolean`?"
},
Number: {
message:
"Avoid using the `Number` type. Did you mean `number`?"
},
String: {
message:
"Avoid using the `String` type. Did you mean `string`?"
},
Symbol: {
message:
"Avoid using the `Symbol` type. Did you mean `symbol`?"
}
}
}
],
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/dot-notation": "off",
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/indent": ["error", "tab"],
"@typescript-eslint/member-ordering": "off",
"@typescript-eslint/naming-convention": [
"error",
{
selector: "variable",
format: ["camelCase", "UPPER_CASE", "snake_case"],
leadingUnderscore: "allow",
trailingUnderscore: "forbid"
},
{
selector: "function",
format: ["camelCase"],
leadingUnderscore: "allow",
trailingUnderscore: "forbid"
},
{
selector: "typeLike",
format: ["PascalCase"]
},
{
selector: "enumMember",
format: ["UPPER_CASE"]
}
],
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/no-unused-expressions": "error",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "error",
"@typescript-eslint/prefer-function-type": "off",
"@typescript-eslint/prefer-namespace-keyword": "off",
"@typescript-eslint/require-await": "warn",
"@typescript-eslint/no-unsafe-assignment": "warn",
"@typescript-eslint/no-unsafe-member-access": "warn",
"@typescript-eslint/restrict-template-expressions": "warn",
"@typescript-eslint/triple-slash-reference": [
"error",
{
path: "always",
types: "prefer-import",
lib: "always"
}
],
"@typescript-eslint/unified-signatures": "error",
"@typescript-eslint/no-shadow": [
"error",
{
hoist: "all"
}
],
complexity: "off",
"constructor-super": "error",
eqeqeq: ["error", "smart"],
"guard-for-in": "off",
"id-denylist": [
"error",
"any",
"Number",
"number",
"String",
"string",
"Boolean",
"boolean",
"Undefined",
"undefined"
],
"id-match": "off",
"import/order": "off",
"jsdoc/check-alignment": "error",
"jsdoc/check-indentation": "error",
"jsdoc/newline-after-description": "error",
"max-classes-per-file": ["error", 1],
"no-bitwise": "error",
"no-caller": "error",
"no-cond-assign": "error",
"no-console": [
"error",
{
allow: [
"warn",
"dir",
"time",
"timeEnd",
"timeLog",
"trace",
"assert",
"clear",
"count",
"countReset",
"group",
"groupEnd",
"table",
"dirxml",
"error",
"groupCollapsed",
"Console",
"profile",
"profileEnd",
"timeStamp",
"context"
]
}
],
"no-debugger": "error",
"no-empty": "error",
"no-eval": "error",
"no-fallthrough": "error",
"no-invalid-this": "off",
"no-new-wrappers": "error",
"no-shadow": "off",
"no-throw-literal": "error",
"no-undef-init": "off",
"no-unsafe-finally": "error",
"no-unused-labels": "error",
"no-var": "error",
"object-shorthand": "error",
"one-var": "off",
"prefer-arrow/prefer-arrow-functions": "error",
"prefer-const": "error",
radix: "off",
"spaced-comment": "off",
"use-isnan": "off",
"valid-typeof": ["error", { requireStringLiterals: false }],
}
]
}}]
}
}
]
};
{
"rules": {
"max-nesting-depth": 4,
"indentation": "tab",
"color-hex-length": "long",
"color-no-invalid-hex": true,
"number-leading-zero": "always",
"function-parentheses-space-inside": "never",
"shorthand-property-no-redundant-values": true,
"rule-empty-line-before": "always",
"block-opening-brace-newline-after": "always",
"block-closing-brace-newline-after": "always",
"no-missing-end-of-source-newline": true,
"color-hex-case": "upper",
"selector-list-comma-newline-after" : "always",
"no-duplicate-at-import-rules" : true,
"comment-no-empty" : true
"comment-no-empty": true,
"indentation": "tab",
"max-nesting-depth": 4,
"no-duplicate-at-import-rules": true,
"shorthand-property-no-redundant-values": true
}
}
{
"name": "@studyportals/code-style",
"version": "2.0.0-alpha.0",
"version": "2.0.0",
"description": "Default linting configurations for the Studyportals repositories",
"main": ".eslintrc.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "npx eslint ./"
},

@@ -28,14 +28,14 @@ "repository": {

"homepage": "https://github.com/studyportals/CodeStyle#readme",
"peerDependencies": {
"eslint": "7.32.0",
"tslint": "6.1.3"
"dependencies": {
"@typescript-eslint/eslint-plugin": "^5.15.0",
"@typescript-eslint/parser": "^5.15.0",
"eslint": "^8.11.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsdoc": "^39.3.3",
"eslint-plugin-prefer-arrow": "^1.2.3",
"typescript": "^4.6.2"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
"@typescript-eslint/eslint-plugin-tslint": "^5.12.0",
"eslint-plugin-jsdoc": "^37.9.4",
"eslint-plugin-prefer-arrow": "^1.2.3",
"typescript": "^4.5.5"
"engines": {
"node": ">=4.9.1 <19.0.0"
}
}
# CodeStyle
The purpose of this repository is to provide standardized configuration files for the most common linters we use in Studyportals repositories. The main usage is in [Super-Linter](https://github.com/studyportals/Super-Linter), which uses these configuration files to run the most important linters on most of our repositories.
Please send pull requests to Stefan Klokgieters or Rob van den Hout if you think you want to suggest changes.
Please send pull requests to [@stefanklokgieters](https://github.com/stefanklokgieters) if you think you want to suggest changes. Never publish changes on NPM without a approval...
## Table of Contents
- [Install](#install)

@@ -16,3 +18,5 @@ - [Linters](#linters)

- [Best Practices](#best-practices)
## Install
You can add CodeStyle as a dependency to your project by running the following command:

@@ -25,5 +29,7 @@

## Linters
### ESLint
[ESLint](https://eslint.org/) is a linter for JavaScript, as well as TypeScript code. It can help find and fix potential problems in your code.
When you install the CodeStyle package you can simply *extend* from the ESLint configuration file inside it.
When you install the CodeStyle package you can simply _extend_ from the ESLint configuration file inside it.

@@ -39,40 +45,86 @@ ```json

```
#### Global variables
When global variables are used in different files than they we're defined in, ESLint will see it as an undefined variable. To solve this problem, you can define the global variables at the top of your file like so:
```javascript
/* global var1, var2, var3 */
```
To avoid this you can define your project's global variables in a custom configuration.
### TSLint
*deprecated* - ESLint can now be used instead
To avoid this you can define your project's global variables in a custom configuration.
[TSLint](https://palantir.github.io/tslint/) is a linter that is specifically meant to lint TypeScript code. When you install the CodeStyle package you can simply *extend* from the TSLint configuration file inside it.
#### Examples
##### Overriding Rules
The example below demonstrates how you can override an existing rule in your `.eslintrc.js`.
```javascript
module.exports = {
extends: "./node_modules/@studyportals/code-style/.eslintrc.js",
rules: {
"@typescript-eslint/array-type": [
"error",
{
default: "generic",
},
],
},
};
```
You can read more about overriding rules [here](https://eslint.org/docs/latest/use/configure/configuration-files#extending-configuration-files).
##### Ignoring Files
The example below demonstrates how you can ignore files in your `.eslintrc.js`.
```javascript
module.exports = {
extends: "./node_modules/@studyportals/code-style/.eslintrc.js",
ignorePatterns: ["**/tests/"],
};
```
Otherwise, you can ignore these files by appending them to your `.eslintignore`. You can read more about ignoring files [here](https://eslint.org/docs/latest/use/configure/ignore).
### StyleLint
[StyleLint](https://stylelint.io/) is our main linter for all styling related files. It can read all types of style related syntax, like SCSS, Sass, Less and SugarSS. When you install the CodeStyle package you can simply _extend_ from the StyleLint configuration file inside it.
```json
// tslint.json
// .stylelintrc.json
{
"extends": "./node_modules/@studyportals/code-style/tslint.json"
"extends": "./node_modules/@studyportals/code-style/.stylelintrc.json"
}
```
### StyleLint
[StyleLint](https://stylelint.io/) is our main linter for all styling related files. It can read all types of style related syntax, like SCSS, Sass, Less and SugarSS. When you install the CodeStyle package you can simply *extend* from the StyleLint configuration file inside it.
#### Examples
##### Overriding Rules
The example below demonstrates how you can override an existing rule in your `.stylelintrc.json`.
```json
// .stylelintrc.json
{
"extends": "./node_modules/@studyportals/code-style/.stylelintrc.json"
"extends": "./node_modules/@studyportals/code-style/.stylelintrc.json",
"rule-empty-line-before": [
"always",
{
"except": "first-nested"
}
]
}
```
### SCSSLint
*deprecated*
##### Ignoring Files
[SCSSLint](https://github.com/sds/scss-lint) is a linter specifically meant for running against rulesets that are specific to `.scss` files. Generally though, we prefer to use [StyleLint](#stylelint) since it supports SCSS natively. When you install the CodeStyle package you can simply reference the SCSSLint configuration file inside it from your custom configuration.
The example below demonstrates how you can ignore files in your `.stylelintrc.json`. However, StyleLint recommends you do so with a `.stylelintignore`, instead. You can read more about this [here](https://stylelint.io/user-guide/configure/#ignorefiles).
```yaml
# .scss-lint.yml
options:
config-file: ./node_modules/@studyportals/code-style/.scss-lint.yml
```json
{
"extends": "./node_modules/@studyportals/code-style/.stylelintrc.json",
"ignoreFiles": ["node_modules/", "**/*.js"]
}
```

@@ -85,6 +137,34 @@

```bash
phpcs-run --standard=./node_modules/@studyportals/code-style/phpcodesniffer.xml ./
phpcs-run --standard=./node_modules/@studyportals/code-style/phpcs.xml ./
```
#### Examples
##### Overriding Rules
The example below demonstrates how you can override an existing rule in your `phpcs.xml` to exclude it.
```xml
<?xml version="1.0"?>
<ruleset name="Custom">
<rule ref="./node_modules/@studyportals/code-style/phpcs.xml">
<exclude name="Generic.Files.LineEndings"/>
<rule/>
</ruleset>
```
##### Ignoring Files
The example below demonstrates how you can ignore files in your `phpcs.xml`
```xml
<?xml version="1.0"?>
<ruleset name="Custom">
<rule ref="./node_modules/@studyportals/code-style/phpcs.xml" />
<exclude-pattern>tests/**/*.php</exclude-pattern>
</ruleset>
```
### PHPMD
[PHPMD](https://phpmd.org/) (or PHP Mess Detector) is a linter for PHP files. It takes a given PHP source code base and look for several potential problems within that source. When you install the CodeStyle package you can reference the PHPMD configuration file inside it.

@@ -97,5 +177,77 @@

#### Examples
##### Overriding Rules
The example below demonstrates how you can override an existing rule in your `phpmd.xml` to exclude it.
```xml
<?xml version="1.0"?>
<ruleset name="Custom">
<rule ref="./node_modules/@studyportals/code-style/phpcs.xml">
<exclude name="Generic.Files.LineEndings"/>
<rule/>
</ruleset>
```
##### Ignoring Files
The example below demonstrates how you can ignore files in your `phpmd.xml`
```xml
<?xml version="1.0"?>
<ruleset name="Custom">
<rule ref="./node_modules/@studyportals/code-style/phpmd.xml" />
<exclude-pattern>tests/**/*.php</exclude-pattern>
</ruleset>
```
### PHPStan
[PHP Static Analysis Tool](https://github.com/squizlabs/PHP_CodeSniffer) is a linter for PHP files. It can discover bugs in the code without running it!. PHPStan can be run from the command line, where the configuration can be referenced.
phpstan.neon configuration from the code style can be included as follows:
```yaml
includes:
- ./node_modules/@studyportals/code-style/phpstan.neon
```
Command to run the phpstan
```bash
phpstan analyse -c phpstan.neon
```
##### Overriding Rules
The example below demonstrates how you can override an existing rule in your `phpstan.neon`.
```yaml
includes:
- ./node_modules/@studyportals/code-style/phpstan.neon
- phpstan-baseline.neon
parameters:
level: 8
```
##### Ignoring Files
The example below demonstrates how you can ignore files in your `phpstan.xml`
```yaml
includes:
- ./node_modules/@studyportals/code-style/phpstan.neon
- phpstan-baseline.neon
parameters:
excludePaths:
- Modules/RankingXDiscipline/ChartBase/rankings_disciplines.php
- TestSuites\PHPUnit\Integration\Router\Handlers\Error\DebugErrorHandlerTest.php
- TestSuites\PHPUnit\Integration\Router\Handlers\Error\DebugXhrErrorHandlerTest.php
- TestSuites\PHPUnit\Integration\Router\IndexTest.php
```
## Best practices
### Whitelisting
Whitelisting source folders is the recommended way of specifying which files should be linted in a project. If certain file within the source folders needs to be skipped, that should be done on file level.
Whitelisting source folders is the recommended way of specifying which files should be linted in a project. If certain file within the source folders needs to be skipped, that should be done on file level.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc