我正在使用很棒的 typescript-eslint和 ESLint。
问题描述:TypeScript ESLint 解析器抱怨src/module.spec.ts不是项目的一部分,这是正确的。我spec.ts从 TypeScripttsconfig.json文件中排除了所有文件,因为它们不需要被转译。
如何使src/module.spec.ts 未转译但仍针对 ESLint进行检查?
my-project\src\module.spec.ts 0:0 错误解析错误:已为@typescript-eslint/parser 设置了“parserOptions.project”。该文件与您的项目配置不匹配:src\module.spec.ts。该文件必须至少包含在提供的项目之一中
我的.eslint.json(精简):
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"env": {
"node": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"project": "tsconfig.json"
},
"plugins": [
"@typescript-eslint"
]
}
Run Code Online (Sandbox Code Playgroud)
我的tsconfig.json:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"declaration": true,
"sourceMap": false,
"outDir": "./dist",
"rootDir": "./src",
"removeComments": true,
"strict": true,
"skipLibCheck": …Run Code Online (Sandbox Code Playgroud) 在嵌套在模型中的对象中定义属性时,CheckBoxFor不受限制?
这是一个例子.我有一个SearchOptions包含List<Star>属性的模型.每个Star都有一个数字,一个名称和一个bool应该受限制的属性:
public class SearchOptions
{
public SearchOptions()
{
// Default values
Stars = new List<Star>()
{
new Star() {Number=1, Name=Resources.Home.Index.Star1,
IsSelected=false},
new Star() {Number=2, Name=Resources.Home.Index.Star2,
IsSelected=false},
new Star() {Number=3, Name=Resources.Home.Index.Star3,
IsSelected=true},
new Star() {Number=4, Name=Resources.Home.Index.Star4,
IsSelected=true},
new Star() {Number=5, Name=Resources.Home.Index.Star5,
IsSelected=true},
};
}
public List<Star> Stars { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在我的强类型视图(of SearchOptions)i循环Stars属性:
@using (Html.BeginForm("Do", "Home"))
{
<fieldset>
<legend>@MVC3TestApplication.Resources.Home.Index.Search</legend>
@{
foreach (Star s in Model.Stars)
{
@Html.CheckBoxFor(m => …Run Code Online (Sandbox Code Playgroud) 我正在开发一个SaaS,其中租户都是真实的和管理员(我们).所以"fornt-end"和"back-end"是一样的.无论如何,根据许多其他问题,bundle是一种以可重用的方式构建项目的方法.
我真的不认为我们的捆绑包会被重用,但我仍然需要一种方法将项目拆分成捆绑包以快速查找我们想要处理的文件.申请应该:
那么,如何组织我的捆绑?可能:
如何改进这种设计?
我有一个抽象的 CRUDController延伸Controller.在我的newAction成功,我想重定向到showAction($slug)使用redirect方法:
return $this->redirect($this->generateUrl($route, $params));
Run Code Online (Sandbox Code Playgroud)
但newAction在实际调用子类中的 UserController,所以我不能指定路线名称$route在我的CRUDController.
class UserController extends CRUDController { }
abstract class CRUDController extends Controller
{
/** @Template */
public function showAction($slug) { }
/** @Template */
public function newAction(Request $request)
{
$model = $this->createModel();
$form = $this->createForm($this->createType(), $model);
if('GET' == $request->getMethod())
return array('form' => $form->createView());
$form->bindRequest($request);
if(!$form->isValid()) return array(
'errors' => $this->get('validator')->validate($model),
'form' => $form->createView()
);
$em = …Run Code Online (Sandbox Code Playgroud) 在<i>首次使用的图标和孩子<div>应该有一个大的图标.任何其他<i>孩子<div>(但不是第一个)应该有一个中等大小的图标:
<div class="row list-item">
<div class="span1">
<i class="icon-user"></i>
</div>
<div class="span3">
<div>
<a href="#">Main Link</a> <i class="icon-male"></i>
</div>
<i class="icon-mail"></i> <a href="#">Link 2</a>
<i class="icon-mobile"></i> <a href="#">Link 3</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
相关CSS:
.list-item > div:first-child {
text-align: center;
}
.list-item i[class^="icon-"], .list-item[class*=" icon-"] {
text-shadow: 3px 1px 2px rgba(0, 0, 0, 0.2);
}
/* Only i with icon-* class, where div is first child */
.list-item > div:first-child > i[class^="icon-"],
.list-item > div:first-child …Run Code Online (Sandbox Code Playgroud) 我正在学习正规表达,所以请跟我一起轻松!
如果不以_(下划线)开头且仅包含单词字符(字母,数字和下划线本身),则用户名被视为有效:
namespace Gremo\ExtraValidationBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
class UsernameValidator extends ConstraintValidator
{
public function validate($value, Constraint $constraint)
{
// Violation if username starts with underscore
if (preg_match('/^_', $value, $matches)) {
$this->context->addViolation($constraint->message);
return;
}
// Violation if username does not contain all word characters
if (!preg_match('/^\w+$/', $value, $matches)) {
$this->context->addViolation($constraint->message);
}
}
}
Run Code Online (Sandbox Code Playgroud)
为了在一个正则表达式中合并它们,我尝试了以下内容:
^_+[^\w]+$
Run Code Online (Sandbox Code Playgroud)
要读作:如果以下划线(最终多于一个)开头并且如果不允许至少一个字符(不是字母,数字或下划线),则添加违规.例如,不适用于"_test".
你能帮我理解我错在哪里吗?
如何在不实际创建实例的情况下检查是否可以使用给定参数成功实例化对象?
实际上我只是检查(没有测试过这段代码,但应该工作正常...)所需参数的数量,忽略类型:
// Filter definition and arguments as per configuration
$filter = $container->getDefinition($serviceId);
$args = $activeFilters[$filterName];
// Check number of required arguments vs arguments in config
$constructor = $reflector->getConstructor();
$numRequired = $constructor->getNumberOfRequiredParameters();
$numSpecified = is_array($args) ? count($args) : 1;
if($numRequired < $numSpecified) {
throw new InvalidFilterDefinitionException(
$serviceId,
$numRequired,
$numSpecified
);
}
Run Code Online (Sandbox Code Playgroud)
编辑:$constructor可以null......
我正在改变我的反射类的可访问标志,这样:
protected function getBaseSubscriptionPeriodReflection()
{
$reflection = new \ReflectionClass('Me\Project\Class');
// Make all private and protected properties accessible
$this->changeAccessibility($reflection, true);
return $reflection;
}
protected function changeAccessibility(\ReflectionClass $reflection, $accessible)
{
$properties = $reflection->getProperties(\ReflectionProperty::IS_PRIVATE
| \ReflectionProperty::IS_PROTECTED);
foreach($properties as $property) {
$property->setAccessible($accessible);
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试设置firstDate属性值时,我得到了异常:
ReflectionException:无法访问非公共成员Me\Project\Class :: firstDate.
这是异常的来源(setValue()方法):
$reflection = $this->getBaseSubscriptionPeriodReflection();
$this->getSubscriptionPeriod($reflection)
protected function getSubscriptionPeriod(\ReflectionClass $reflection)
{
$period = $reflection->newInstance();
// Reflection exception here
$reflection->getProperty('firstDate')->setValue($period, 'foo');
return $period;
}
Run Code Online (Sandbox Code Playgroud) getCurrentOrDefaultLocale()可以从控制器或命令行脚本调用在我的服务中定义的函数.
request从CLI 访问服务会引发异常,我正在使用它来检测CLI调用.然而,仅为此目的捕获异常对我来说似乎很糟糕.
有没有可靠的方法来检查请求是否可以在当前上下文中执行(执行,浏览器与CLI)?
/**
* @return string
*/
protected function getCurrentOrDefaultLocale()
{
try {
$request = $this->container->get('request');
}
catch(InactiveScopeException $exception) {
return $this->container->getParameter('kernel.default_locale');
}
// With Symfony < 2.1.0 current locale is stored in the session
if(version_compare($this->sfVersion, '2.1.0', '<')) {
return $this->container->get('session')->getLocale();
}
// Symfony >= 2.1.0 current locale from the request
return $request->getLocale();
}
Run Code Online (Sandbox Code Playgroud) 如果您使用Node.js编程几天,即使有很好的文档q框架也很难理解.但我喜欢了解它!
var Q = require('q');
var fs = require('fs');
// Make the promise manually (returns a value or throws an error)
var read1 = fs.readFile(fname, enc, function (err, data) {
if(err) throw err;
return data;
});
// Convenient helper for node, equivalent to read1?
var read2 = Q.nfbind(fs.readFile);
// Uh?!
var read3 = function (fname, enc) {
var deferred = Q.defer();
fs.readFile(fname, enc, function (error, text) {
if (error) {
deferred.reject(new Error(error));
} else {
deferred.resolve(text);
}
return …Run Code Online (Sandbox Code Playgroud) php ×3
symfony ×3
reflection ×2
asp.net-mvc ×1
asynchronous ×1
binding ×1
checkbox ×1
css ×1
css3 ×1
eslint ×1
eslintrc ×1
locale ×1
node.js ×1
preg-match ×1
promise ×1
q ×1
razor ×1
regex ×1
request ×1
session ×1
symfony-2.1 ×1
tsconfig ×1
typescript ×1
username ×1